Error when adding row in access

bluejaguar456

Well-known member
Joined
Aug 22, 2006
Messages
47
Hey Guys,

I am getting an error message when trying to add some information to my database.

I keep getting the, syntax error in insert into statement

Below is my code:

Code:
Public Class Form1
    Dim con As New OleDb.OleDbConnection
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sql As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        Dim dsNewRow As DataRow

        dsNewRow = ds.Tables("Users").NewRow()

        dsNewRow.Item("frst123") = txtfirstname.Text

        ds.Tables("Users").Rows.Add(dsNewRow)

        da.Update(ds, "Users")

        MsgBox("New Record added to the Database")
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\Eddy\My Documents\users.mdb"
        con.Open()

        sql = "SELECT * FROM Users"
        da = New OleDb.OleDbDataAdapter(sql, con)

        da.Fill(ds, "Users")

        txtfirstname.Text = ds.Tables("Users").Rows(0).Item(0)

    End Sub
End Class

Please could you identify my problem is possible thanks.
 
I have not used the CommandBuilder very much but I think this should be possible, is there any way you can post the generated INSERT command?
 
The CommandBuilder class builds your Update, Insert, and Delete commands based on the Select statement you give it.

What is the SQL the CommandBuilder is creating? Post there here and Ill have a look.
 
When it works its great, but when it doesnt it causes lots of confusion becaues people dont always understand whats going on behind the scenes.

If you post the code it is generating Ill take a look and see if I cant help you understand whats going on.
 
Code:
INSERT INTO table_name VALUES ("value")

thats the code that is used to insert into database i got it off the internet
 
Back
Top