bluejaguar456 Posted October 29, 2008 Posted October 29, 2008 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. Quote
Nate Bross Posted October 30, 2008 Posted October 30, 2008 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? Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
bluejaguar456 Posted October 30, 2008 Author Posted October 30, 2008 what do you mean by the generated insert code? Quote
bluejaguar456 Posted October 30, 2008 Author Posted October 30, 2008 or do you know of any other way to ad a record into an access database? Thanks Quote
Nate Bross Posted October 30, 2008 Posted October 30, 2008 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. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Nate Bross Posted October 31, 2008 Posted October 31, 2008 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. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
bluejaguar456 Posted October 31, 2008 Author Posted October 31, 2008 INSERT INTO table_name VALUES ("value") thats the code that is used to insert into database i got it off the internet Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.