incorrect date entered from vb.net to sql server 2000

osani

Member
Joined
Apr 7, 2005
Messages
14
Programming Experience
1-3
Hi

I'm not sure if this is a VB question or an SQL server question but here goes...

I have a db created in SQL Server 2000 with a VB.net interface and I am tring to input a date. The datatype is datetime and I have code that corrects a typo if the date is not valid. I even put in msgbox to tell me what me code and the system is doing - first it tells me the systems date Now() and then tells me the value of the textbox so that either would be valid entries, but then when I look at the entry in the database no matter what is entered it puts in 1/1/1900 as the date - what the heck is that?! Here is the peice of code, any advice will help.
***Date verification***
If IsDate(textdate.Text) Then
textdate.Text = FormatDateTime(textdate.Text, DateFormat.ShortDate)
Else
textdate.Text = FormatDateTime(Now(), DateFormat.ShortDate)
EndIf
***SQL statement***
Dim str AsString = "insert demographic(accnum, clinic, qdate) values (" & _
acc & "," & _
preparestr(textclinic.Text) & "," & _
textdate.Text & ")"


mycommand = New SqlCommand(str, myconnection)
mycommand.ExecuteNonQuery()


Thanks.
 

vbArch

Member
Joined
Apr 11, 2005
Messages
11
Programming Experience
10+
Dates are weird try this

Dim str AsString = "insert demographic(accnum, clinic, qdate) values (" & _
acc & "," & _
preparestr(textclinic.Text) & ",#" & _
textdate.Text & "#)"
 

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
It's an SQL problem as it's an insert statment your having problems with.
Please only post questions once.
Incase you didn't see my other post it's Insert INTO.
 
Top Bottom