Date/Time problem

  • Thread starter Thread starter John Devlon
  • Start date Start date
J

John Devlon

Hi,

I've created a class With a few properties of type "date".
I also have a SQL-database (which I can't change) with columns of type
"datetime"

when I use ...

clsInfo.date = now()

.... I can't pas the date to the database without errors...


When I create a date property of type string and I use it like this ...

clsInfo.dateString = "2006-12-2"

.... it works fine...

Anyone any idea's ? Do I have to convert the date to string before sending
it to the database ?

thanx

John
 
Hello John,

There's no need to convert it to string..

Dim tConnection As SqlConnection = New SqlConnection("connection string here")
Dim tCommand as SqlCommand = New SQlCommand

With tCommand
.Connection = tConnection
.CommandType = CommandType.Text
.CommandText = "INSERT INTO someTable (dateField) VALUES (@dateValue)
.Parameters.AddWithValue("@dateValue", Now)
End With

tConnection.Open
tCommand.ExecuteNonQuery
tConnection.Close


Enjoy,
-Boo
 
In addition to Boo,

As you have done it correct of course and your DateTime is a real DateTime
field in your database and not a string as sometimes is done.

Cor
 
Back
Top