Results 1 to 6 of 6

Thread: [2005] Syntax error in INSERT INTO..in ado.net

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    8

    Resolved [2005] Syntax error in INSERT INTO..in ado.net

    hi,
    im trying out a simple code in which i add data to my database.....
    Code:
      Dim dr As DataRow
            strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\rs232\rem.mdb;User Id=;Password=;"
    
            Dim cmd As New OleDbCommand("INSERT INTO reminderdata (datetime, reminder)VALUES('" & txtdate.Text & "','" & txtreminder.Text & "')", New OleDbConnection(strconn))
    
            cmd.Connection.Open()
            cmd.ExecuteNonQuery()
            cmd.Connection.Close()
    but its giving me error saying Syntax error in INSERT INTO statement

    so i tried the code given here

    Code:
    dr = ds.Tables(0).NewRow()  'Gets a reference to a new row.
            dr("datetime") = txtdate.Text
            dr("reminder") = txtreminder.Text
    
    
           ds.Tables(0).Rows.Add(dr)
           da.Update(ds)
           ds.AcceptChanges()
    and declared the insert command as

    Code:
    da.InsertCommand = New OleDbCommand("INSERT INTO reminderdata(datetime, reminder) VALUES(@datetime,@reminder)")
            da.InsertCommand.Connection = conn
            da.InsertCommand.Parameters.Add("@datetime", OleDbType.VarChar, 40, "datetime")
            da.InsertCommand.Parameters.Add("@reminder", OleDbType.VarChar, 40, "reminder")

    but i got the same error.....

    plz help me resolve the error.....
    Last edited by crystalsnehal; Apr 4th, 2008 at 07:01 AM.

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