Results 1 to 8 of 8

Thread: Adding a record to a Database?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Posts
    28

    Question Adding a record to a Database?

    Hi I'v been trying to insert a record to a database using this code:

    Set editCmd = Server.CreateObject("ADODB.Command")
    editCmd.ActiveConnection = "dsn=Message;"
    editCmd.CommandText = "insert into Posts (Date_added,Name,Email,Subject,Text) values ('5/29/2001 8:00:24 PM','Stephen','[email protected]','Test','Testing.') "
    editCmd.Execute
    editCmd.ActiveConnection.Close
    to create a Message Board, but I always get this error :

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

    [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

    /syt/BillBoard/Index.asp, line 91

    I'm totaly clules why this is happening


    Help!!!!!!!!!!!

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Location
    The Lone Star State
    Posts
    183
    Shouldn't the date be in a form other than as a string surrounded by single quotes??
    !

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Posts
    28
    I dont think " ", / or : are not alowed though.

  4. #4
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    have you referenced all the needed references.
    I.e ole driver etc.

  5. #5
    Lively Member
    Join Date
    Jan 2001
    Location
    india
    Posts
    109

    hey dont worry

    It is nothing more than a syntax error ,
    So just use cdate before your date expression so that
    you won't get error i think,

    if you get error still

    check the date expression using Isdate before inserting into database

    hope it works

    Bye
    I respect love and lovers ,but it should be possesive .
    I love friendship and friends but it should be true.

  6. #6
    Lively Member
    Join Date
    Jan 2001
    Location
    india
    Posts
    109

    Hey again Aniz with another solution

    Your sql fine ,it has no error,The main thing when your passing
    a sql through Ado it doesn't accept the field names if it is a reserved word. Your sql has reserve word TEXT as a field name ,
    When Ado finds this text as one of the field name it generates the error



    first you go to the table and change the FIELDNAME TEXT to TTEXT
    then just try the modified sql now

    editcmd.CommandText = "insert into Posts (date_added,Name,Email,Subject,ttext) values ('5/29/2001 8:00:24 PM','Stephen','[email protected]','Test','Testing.') "




    hope this helps much.
    bye.
    I respect love and lovers ,but it should be possesive .
    I love friendship and friends but it should be true.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Posts
    28

    Smile

    Thanks Sooooooooo much!!!!!!!!!!

  8. #8
    nullus
    Guest
    Or rather than renaming the field, just use this (ie. put brackets around dodgy words):

    Code:
    editcmd.CommandText = "insert into Posts (date_added,Name,Email,Subject,[Text]) values ('5/29/2001 8:00:24 PM','Stephen','[email protected]','Test','Testing.')"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width