Insert DateTime Value In DB Table?

Discussion in 'ASP .Net' started by Arpan, Aug 17, 2006.

  1. Arpan

    Arpan Guest

    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
     
    Arpan, Aug 17, 2006
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    >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
    >
     
    Kevin Spencer, Aug 17, 2006
    #2
    1. Advertising

  3. Arpan

    Arpan Guest

    > 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" <> wrote in message
    > news:...
    > >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
    > >
     
    Arpan, Aug 19, 2006
    #3
  4. 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" <> wrote in message
    news:...
    >> 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" <> wrote in message
    >> news:...
    >> >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
    >> >

    >
     
    Juan T. Llibre, Aug 19, 2006
    #4
  5. Arpan

    Arpan Guest

    > 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" <> wrote in message
    > news:...
    > >> 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" <> wrote in message
    > >> news:...
    > >> >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
    > >> >

    > >
     
    Arpan, Aug 19, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    743
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    580
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    417
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    363
    Martin
    Dec 27, 2008
  5. Replies:
    2
    Views:
    789
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page