wat is the problem here

cmd1 = New OleDbCommand("Update tblParking SET status = 'Available' Where exp_date <='" & Date.Today & "'", cn)

i want update the field status to "Available" when exp_date is less then todays date..
wat do i need to do.

Edited 6 Years Ago by muhamin: n/a

If this is a date field, try # instead of '

cmd1 = New OleDbCommand("Update tblParking SET status = 'Available' Where exp_date <=#" & Date.Today & "#", cn)

i already fixed it, this all cause of the damn deference between VB.NET time format and SQL time thing, so i changed the whole thing to sql time, from all the queries from insert/Update too. so now no errors,

SQL thing is like this

cmd1 = New OleDbCommand("Update tblParking SET status = 'Available' Where exp_date <= now() ", cn)

Good to see you got it working Muhamin but be careful of subtle differences, especially between today's date and today's date and time:


the oledb SQL thing:
"Where exp_date <= Date()" - today's date
"Where exp_date <= now()" - today's date and time

The vb.net thing:

for today's date use:

cmd1 = New OleDbCommand("Update tblParking SET status = 'Available' Where exp_date <=#" & Date.Today & "#", cn)cmd1 = New OleDbCommand("Update tblParking SET status = 'Available' Where exp_date <=#" & Date.Today & "#", cn)

for today's date and time use:

cmd1 = New OleDbCommand("Update tblParking SET status = 'Available' Where exp_date <=#" & Date.Today & "#", cn)cmd1 = New OleDbCommand("Update tblParking SET status = 'Available' Where exp_date <=#" & Date.Now & "#", cn)

The reason your previous code didn't work was because you used ' instead of #

This article has been dead for over six months. Start a new discussion instead.