Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

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.

Posted
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?

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

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 I'll have a look.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

When it works its great, but when it doesn't it causes lots of confusion becaues people don't always understand whats going on behind the scenes.

 

If you post the code it is generating I'll take a look and see if I can't help you understand whats going on.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...