Sending command with DateTime

Discussion in 'ASP .Net' started by Steffen Loringer, Feb 18, 2004.

  1. Hi,

    I'm using SQLCmd = New SqlClient.SqlCommand and then
    SQLCommand.CommandType = CommandType.Text

    My problem is as follows: I like to update a table in SQL Server with a
    column of the type DateTime.
    so I used "UPDATE MyTable SET TheTime=" & ActualTime.ToString. But it's
    not working. What is the way to send a DateTime datatype to SQL Server??

    Thanks a lot

    Steffen
    Steffen Loringer, Feb 18, 2004
    #1
    1. Advertising

  2. Steffen Loringer

    Anatoly Guest

    1) Use parameter

    sqlcmd.Parameters.Add([param name], sqldbtype.DateTime).Value = MyDate

    2) Cast datetime to 'yyyyMMdd' format

    "Update ... set TheTime = " & ActualTime.toString('yyyyMMdd')

    HTH

    "Steffen Loringer" <> wrote in message
    news:c0vnsu$1c9nke$-berlin.de...
    > Hi,
    >
    > I'm using SQLCmd = New SqlClient.SqlCommand and then
    > SQLCommand.CommandType = CommandType.Text
    >
    > My problem is as follows: I like to update a table in SQL Server with a
    > column of the type DateTime.
    > so I used "UPDATE MyTable SET TheTime=" & ActualTime.ToString. But it's
    > not working. What is the way to send a DateTime datatype to SQL Server??
    >
    > Thanks a lot
    >
    > Steffen
    >
    Anatoly, Feb 18, 2004
    #2
    1. Advertising

  3. Hi, Steffen Loringer,

    You should use parameters to avoid problems:

    http://msdn.microsoft.com/library/e...taSqlClientSqlCommandClassParametersTopic.asp

    Hope this helps
    Martin
    "Steffen Loringer" <> wrote in message
    news:c0vnsu$1c9nke$-berlin.de...
    > Hi,
    >
    > I'm using SQLCmd = New SqlClient.SqlCommand and then
    > SQLCommand.CommandType = CommandType.Text
    >
    > My problem is as follows: I like to update a table in SQL Server with a
    > column of the type DateTime.
    > so I used "UPDATE MyTable SET TheTime=" & ActualTime.ToString. But it's
    > not working. What is the way to send a DateTime datatype to SQL Server??
    >
    > Thanks a lot
    >
    > Steffen
    >
    Martin Dechev, Feb 18, 2004
    #3
    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:
    674
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    513
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    368
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    315
    Martin
    Dec 27, 2008
  5. Replies:
    2
    Views:
    736
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page