468,765 Members | 1,384 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

Insert DateTime Value In DB Table?

A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int
column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB"
(datetime). Now when I am trying to add a new row using the following
INSERT statement:

sqlDapter.InsertCommand = New SqlCommand
sqlDapter.InsertCommand.CommandText = "INSERT INTO UserDetailss
VALUES('bobby','simpson','" & Now() & "')"
sqlDapter.InsertCommand.Connection = sqlConn
sqlDapter.Update(dSet, "UserDetails")
'Response.Write("INSERT INTO UserDetailss VALUES('bobby','simpson','" &
Now() & "')"

the following error gets generated pointing to the Update line:

The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.

I even tried using the different DateTime Format functions but none of
them work. WHere am I going wrong?

Thanks

Arpan

Aug 17 '06 #1
4 8466
DateTime.Now is a DateTime value, not a string. Try using
DateTime.Now.ToString()

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int
column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB"
(datetime). Now when I am trying to add a new row using the following
INSERT statement:

sqlDapter.InsertCommand = New SqlCommand
sqlDapter.InsertCommand.CommandText = "INSERT INTO UserDetailss
VALUES('bobby','simpson','" & Now() & "')"
sqlDapter.InsertCommand.Connection = sqlConn
sqlDapter.Update(dSet, "UserDetails")
'Response.Write("INSERT INTO UserDetailss VALUES('bobby','simpson','" &
Now() & "')"

the following error gets generated pointing to the Update line:

The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.

I even tried using the different DateTime Format functions but none of
them work. WHere am I going wrong?

Thanks

Arpan

Aug 17 '06 #2
DateTime.Now is a DateTime value, not a string. Try using
DateTime.Now.ToString()
Kevin, DateTime.Now.ToString() still generates the same out-of-range
error & why wouldn't it? The data type of the column named "DOB" in the
DB table (& hence in the DataSet as well) is "datetime" which means SQL
Server is expecting a datetime record in that column; so converting it
to string - how will that work?

Please correct me if I am wrong.

Thanks,

Regards,

Arpan

Kevin Spencer wrote:
DateTime.Now is a DateTime value, not a string. Try using
DateTime.Now.ToString()

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int
column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB"
(datetime). Now when I am trying to add a new row using the following
INSERT statement:

sqlDapter.InsertCommand = New SqlCommand
sqlDapter.InsertCommand.CommandText = "INSERT INTO UserDetailss
VALUES('bobby','simpson','" & Now() & "')"
sqlDapter.InsertCommand.Connection = sqlConn
sqlDapter.Update(dSet, "UserDetails")
'Response.Write("INSERT INTO UserDetailss VALUES('bobby','simpson','" &
Now() & "')"

the following error gets generated pointing to the Update line:

The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.

I even tried using the different DateTime Format functions but none of
them work. WHere am I going wrong?

Thanks

Arpan
Aug 19 '06 #3
Is the date format whch you are trying to insert the same
format as your SQL Server's default date format ?


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
>DateTime.Now is a DateTime value, not a string. Try using
DateTime.Now.ToString()

Kevin, DateTime.Now.ToString() still generates the same out-of-range
error & why wouldn't it? The data type of the column named "DOB" in the
DB table (& hence in the DataSet as well) is "datetime" which means SQL
Server is expecting a datetime record in that column; so converting it
to string - how will that work?

Please correct me if I am wrong.

Thanks,

Regards,

Arpan

Kevin Spencer wrote:
>DateTime.Now is a DateTime value, not a string. Try using
DateTime.Now.ToString()

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googleg roups.com...
>A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int
column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB"
(datetime). Now when I am trying to add a new row using the following
INSERT statement:

sqlDapter.InsertCommand = New SqlCommand
sqlDapter.InsertCommand.CommandText = "INSERT INTO UserDetailss
VALUES('bobby','simpson','" & Now() & "')"
sqlDapter.InsertCommand.Connection = sqlConn
sqlDapter.Update(dSet, "UserDetails")
'Response.Write("INSERT INTO UserDetailss VALUES('bobby','simpson','" &
Now() & "')"

the following error gets generated pointing to the Update line:

The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.

I even tried using the different DateTime Format functions but none of
them work. WHere am I going wrong?

Thanks

Arpan

Aug 19 '06 #4
Is the date format whch you are trying to insert the same
format as your SQL Server's default date format ?
Juan, the datetime records already present in SQL Server look like
this:

19/08/2006 11:17:45 AM

& when I do a

Response.Write(Now())

the output is exactly the same i.e.

19/08/2006 11:17:45 AM

So I guess they are the same, aren't they?

Thanks,

Regards,

Arpan

Juan T. Llibre wrote:
Is the date format whch you are trying to insert the same
format as your SQL Server's default date format ?


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
DateTime.Now is a DateTime value, not a string. Try using
DateTime.Now.ToString()
Kevin, DateTime.Now.ToString() still generates the same out-of-range
error & why wouldn't it? The data type of the column named "DOB" in the
DB table (& hence in the DataSet as well) is "datetime" which means SQL
Server is expecting a datetime record in that column; so converting it
to string - how will that work?

Please correct me if I am wrong.

Thanks,

Regards,

Arpan

Kevin Spencer wrote:
DateTime.Now is a DateTime value, not a string. Try using
DateTime.Now.ToString()

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int
column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB"
(datetime). Now when I am trying to add a new row using the following
INSERT statement:

sqlDapter.InsertCommand = New SqlCommand
sqlDapter.InsertCommand.CommandText = "INSERT INTO UserDetailss
VALUES('bobby','simpson','" & Now() & "')"
sqlDapter.InsertCommand.Connection = sqlConn
sqlDapter.Update(dSet, "UserDetails")
'Response.Write("INSERT INTO UserDetailss VALUES('bobby','simpson','" &
Now() & "')"

the following error gets generated pointing to the Update line:

The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.

I even tried using the different DateTime Format functions but none of
them work. WHere am I going wrong?

Thanks

Arpan
Aug 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Martin | last post: by
7 posts views Thread by Arek | last post: by
1 post views Thread by NathanV | last post: by
6 posts views Thread by rn5a | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.