Results 1 to 4 of 4

Thread: Error adding new records to table (OleDb)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Posts
    416

    Error adding new records to table (OleDb)

    Ok... All I'm trying to do is add a record to the database and it's giving me a "Syntax Error in INSERT TO statement"

    The tbl_Guestbook_Entries table has 5 fields:

    ID - AutoNumber
    Date - String
    Name - String
    Email - String
    Message - String

    Here's the code:

    Code:
            ' setup connection and command
            Dim dbCon As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
                Server.MapPath("~/Guestbook.mdb"))
            Dim dbCmd As New OleDbCommand("INSERT INTO tbl_Guestbook_Entries (Date,Name,Email,Message) VALUES ('" & _
                DateTime.Now.Date.ToString().Substring(0, 10) & "','" & txtName.Text & "','" & txtEmail.Text & _
                "','" & txtMessage.Text & "')", dbCon)
    
            ' execute query to add new record (guestbook entry)
            dbCmd.Connection.Open()
            dbCmd.ExecuteNonQuery()
            dbCmd.Connection.Close()
    
            ' clear text fields
            txtName.Text = ""
            txtEmail.Text = ""
            txtMessage.Text = ""
    
            ' display guestbook entries
            FillMessageTable()
    I'm pretty sure the syntax of my INSERT TO statement is correct... Anyone see what's causing the problem?

  2. #2
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    Some(all?) of your DB column names are reserved words.

    Date and Name will surely choke everything.

    ID, Email and Message are fairly generic also, and should probably be changed.


    John

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Posts
    416
    Ok, the names were the cause of that problem... But now I'm getting this error:

    --------------------
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.OleDb.OleDbException: Operation must use an updateable query.

    Source Error:

    Line 89: ' execute query to add new record (guestbook entry)
    Line 90: dbCmd.Connection.Open()
    Line 91: dbCmd.ExecuteNonQuery()
    Line 92: dbCmd.Connection.Close()
    ---------------------

    I'm thinking it's something to do with file permissions. Because my code appears fine. I'm going to try and mess around with permissions now... Anyone's input would be great
    Last edited by Eras3r; Feb 12th, 2003 at 07:09 PM.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Posts
    416
    Solved problem -- Just needed to change aspnet_wp account to Administrator.

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