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
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