1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

asp date() to SQL Server

Discussion in 'C#' started by moiseszaragoza, Sep 2, 2009.

  1. #1
    I am trying to insert into a datefield in the SQL Server
    but i get this error



    Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

    [Microsoft][SQL Native Client][SQL Server]Operand type clash: text is incompatible with date

    /admin/news.asp, line 96


    the value of my date is 9/2/2009
     
    moiseszaragoza, Sep 2, 2009 IP
  2. alex021

    alex021 Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Its hard to say without looking at the code, but it seems like there is a mismach between date formats. Check what date format is outputed by the code and check what date format is required by the database and make sure they are correct
     
    alex021, Sep 2, 2009 IP
  3. vic_89

    vic_89 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well you can always format the date into any format you prefer...for example
    myDate.ToString("yyyy-MM-dd") would give you something like "2009-09-28"
     
    vic_89, Sep 26, 2009 IP
  4. MaceWin

    MaceWin Peon

    Messages:
    38
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try formatting the date into dd/MMM/yyyy format, (eg - 28/Sep/2009) before you insert it into the SQL Server. That way, no matter how you have your dates set up in MSSQL (Date/Month/Year or Month/Day/Year) the insert will work.
     
    MaceWin, Sep 27, 2009 IP
  5. rkstech

    rkstech Active Member

    Messages:
    195
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    73
    #5
    Looks like a formatting error.

    Have a look at cast and convert.

    Google it and there are plenty of resources
     
    rkstech, Sep 30, 2009 IP
  6. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #6
    just use the GETDATE() internal method in sql server - as in your sql string would be
    "INSERT INTO TBL (NAME, DATE) VALUES ('Bob Barker', GETDATE())"
     
    ccoonen, Sep 30, 2009 IP
  7. topman

    topman Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    use FormatDateTime(todaysDate,2) to format your data in correct form
     
    topman, Nov 7, 2009 IP
  8. makeitlive

    makeitlive Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    try formating your date into "yyyy/MM/dd" format.
     
    makeitlive, Dec 21, 2009 IP