Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Insert DateTime Value In DB Table?

Reply
Thread Tools

Insert DateTime Value In DB Table?

 
 
Arpan
Guest
Posts: n/a
 
      08-17-2006
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

 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      08-17-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
 
 
 
Arpan
Guest
Posts: n/a
 
      08-19-2006
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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
> >


 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      08-19-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed) 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
>> >

>



 
Reply With Quote
 
Arpan
Guest
Posts: n/a
 
      08-19-2006
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed) 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
> >> >

> >


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [2.4.4] creating a datetime.datetime from an XML xs:dateTime skip@pobox.com Python 2 01-06-2009 01:31 PM
[2.4.4] creating a datetime.datetime from an XML xs:dateTime Martin Python 0 12-27-2008 08:08 PM
mx.DateTime to datetime.datetime mp Python 1 07-28-2006 10:57 PM
datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Christos TZOTZIOY Georgiou Python 3 09-13-2003 10:44 AM
RE: datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Tim Peters Python 0 09-09-2003 12:57 AM



Advertisments