Home » Asp.net

convert date from datetime picker to sql format

I have an application that uses a time date picker control to display a date from a sql (sql 2000) table. Casting from the table to the control works fine, but writing a selected date from the control back to the database does not, I was under the impression that a datatype 'date' in VB would be compatible with SQL datetime datatime, and obviously it is from sql to vb as the date is correctly displayed in the control reading from the table. How do I need to convert the value from the date time picker control to write into sql ? 


2 Answers Found


Answer 1


Try something like:

' Use Convert.ToDateTime function.

Dim dt As DateTime = Convert.ToDateTime("04/11/2010")

Hope this helps.



Answer 2

first you need to chech in which format your date time picker date is displaying(suppose if its displaying in dd/MM/yyyy), in that case your sql will take date format in (MM/dd/yyyy). which will give casting problem. just check which format your date is displaying.



<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure