Updating date

cmd = New SqlCommand("update tb_projectpara set customer='" & cmbCustomer.Text & "', date = '" & dtpEndDate.Value.Date & "' where projectno='" & txtProjectNo.Text & "' and date='" & dat2 & "' and customer='" & cmbCustomer.Text & "'", con)
cmd.ExecuteNonQuery()
''
Everything works fine except date,its not updating in the database.
it is datepicker component.



plz chk it out



Comments

  • seancampbellseancampbell Pennsylvania, USA
    There are two things I see that could be causing this not to update.

    The first one is ProjectNo = 'value'. If projectNo is a number field (int, float, etc) then sending it something in single quotes will cause it to fail. I don't know what you have this feild configured as, so it's something to look into...

    The second one is "where date='" & dat2 & "'". If you're using SQL Server, datetime values store exact times and dates. If you want to update a record, based on the date, you have to do something like this:
    [code]
    Dim BegDate As Date = CDate(Format(Now, "MM/dd/yyyy") & " 12:00:00AM")
    Dim EndDate As Date = CDate(Format(Now, "MM/dd/yyyy") & " 11:59:59PM")
    cmd = New SqlCommand("UPDATE tb_projectpara SET customer = '" & cmbCustomer.Text & "', date = '" & dtpEndDate.Value.Date & "' WHERE projectno = '" & txtProjectNo.Text & "' AND (date >= '" & BegDate.ToString & "' AND date <= '" & EndDate.ToString & "') AND customer = '" & cmbCustomer.Text & "'", con)
    cmd.ExecuteNonQuery()
    [/code]

    I think that is your problem. If that doesn't work. I suggest trying to get your SQL Statement working in SQL Management Studio, or with Visual Studio's built in Server Explorer and SQL Query Writer to figure out what may be wrong with your SQL Syntax.

    Happy coding,
    FireSickle.com
  • The datatype i am using is datetime.I tried the code that you have given to me.but its not updating
  • Thanku ,yes i got
  • Is this for a movie rental project? If so I may need some clarification/help. I'll be online racking my brain with this on Saturday and one that is due on Sunday too. I am not doing too well in this class.
  • Sorry for double posting. I thought it didn't go through and ended up going through 2*. I am not sure how to or if i can delete.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories