Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

In VB.NET , I tried to update "date" filed in my table form my Datetimepicker from a Windows form. The SQL is :

 

strSQL = "UPDATE Employee SET Dob = Datetimepicker1.value WHERE EmployeeID = 10001"

 

However , the DOB field is always updated as 01/01/1900

 

The databse I used in MSDE , the Dob field is smalldatetime .

 

 

I tried get many get answer from some reference book ,but most of example are in updating String and Integer . I really need someone who knows the ways to update "date" field. Thank you .

Posted

This might help:

 

Have you set the date format of the datetimepicker control to the same as your database

 

datetimepicker1.customformat = 'whatever your date format should be

 

Also in SQL I would create a variable (e.g. varDate) set to the value of the datetimepicker value e.g.:

 

Dim varDate = datetimepicker1.value

 

And then use that within the SQL as:

 

strSQL = "UPDATE Employee SET Dob = #" & varDate & "# WHERE ....."

Visit: VBSourceSeek - The VB.NET sourcecode library

 

 

"A mere friend will agree with you, but a real friend will argue."
Posted

I alway convert my dates to double before putting into database using this method

 

DateTimePicker1.Value.ToOADate()

 

You can then be sure no matter what format or reginal settings are on the date, the date value is correct

 

SQL:

strSQL = "UPDATE Employee SET Dob = " & Datetimepicker1.Value.ToOADate() " & WHERE EmployeeID = 10001"

 

Andy

Code today gone tomorrow!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...