Home All Groups Group Topic Archive Search About
Author
30 Aug 2006 1:03 AM
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

Author
30 Aug 2006 1:20 AM
GhostInAK
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

Show quoteHide quote
> 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
>
Author
30 Aug 2006 5:27 AM
Cor Ligthert [MVP]
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

Show quoteHide quote
"GhostInAK" <ghosti***@gmail.com> schreef in bericht
news:be1391bf15dbd8c899a680582a6f@news.microsoft.com...
> 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
>
>> 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
>>
>
>