473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Date/Time problem

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


Aug 30 '06 #1
2 838
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

Aug 30 '06 #2
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

"GhostInAK" <gh*******@gmail.comschreef in bericht
news:be**************************@news.microsoft.c om...
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


Aug 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Raghu | last post by:
Hello... I am running into a problem while running a query..can some1 help.. this is the query : ************** SELECT * from Table S where S.dtDate1 BETWEEN...
18
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
2
by: Riegn Man | last post by:
I have a problem with access and our time clocks. We have time clocks that put out a .log file with the badge swipes for everybody. There is one .log file for each day. I am pulling that data...
6
by: Geoff Cox | last post by:
Hello, at the moment I can add the combined date and time into MySQL using php $dt1 = date("Y-m-d H:i:s"); is it possible to add the date and time separately? I thought it might be
10
by: WebCM | last post by:
There is a function: http://paste.ubuntu.com/21865 It needs GMT date in YYYY-MM-DD HH:MM:SS format - in SQL: datetime. If date is the same as today, the function returns "Today". There is one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.