OmarMallat

please let me know what is the problem here...

Private Sub Add(cn as Data.SqlClient.SqlConnection)

Dim cm As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand("Insert Into FatwaRequest (aTitle, aDate) Values ('Test', " & Now.Date & ")", cn)

cn.Open()

cm.ExecuteNonQuery()

cn.Close()

End Sub

the problem is that the date was inserted as 01/01/1900 12:00:00 AM. and not the current date

I have sql server 2005 developer edition. and when I execute the same query

Insert Into FatwaRequest (aTitle, aDate) Values ('Test', 07/06/2007)"

also the date was inserted as 01/01/1900 12:00:00 AM. and not the date I wrote in the query

and if I write the date and time in the query it give me error:

Insert Into FatwaRequest (aTitle, aDate) Values ('Test', 07/06/2007 02:10:13 AM)"

the error was: Incorrect syntax near '02'

please let me know what is wrong.....




Re: Visual Basic Language SQL Insert command ignore the date value

hsivaram

Hi,

Date and time must be inserted under Single Quotes..

Dim cm As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand("Insert Into FatwaRequest (aTitle, aDate) Values ('Test', '" & Now.Date & "')", cn)

cn.Open()

cm.ExecuteNonQuery()

cn.Close()

End Sub





Re: Visual Basic Language SQL Insert command ignore the date value

Manu_Raj

Hi OmarMallat,

Your problem indicates that, the issue is with the datatype of the field "aDate". If you choosen aDate as Date type, then you need to specify the formate also. Or better you should take this field as String type (If you are not performing any date functions) and on VB you should write below query:

"Insert Into FatwaRequest (aTitle, aDate) Values ('Test', ' & Format(Now, "DD/MM/YYYY" & ')"

Hope it helps a bit...