473,385 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

VB 2003.net Syntax error in INSERT INTO statement

10
Hi, i am trying to add a new row into a microsoft access database and cant understand why it wont work. Can anyone please help me understand what this means? The error message says:

************** Exception Text **************
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at movie_rentals.employeeadd.Button2_Click(Object sender, EventArgs e) in C:\Users\Rik\Desktop\Riks work\VB\pictures for vb\DVDs r us\Employee Add.vb:line 409
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Actual Code **************
Try

Dim connStr As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = dvd.mdb"
Dim aDataTable As New DataTable
Dim squlStr As String = "SELECT * From Users"
Dim oleDbStaffAdapter As New OleDb.OleDbDataAdapter(squlStr, connStr)

aDataTable.Clear()

oleDbStaffAdapter.Fill(aDataTable)
Dim MyNewRow As DataRow = aDataTable.NewRow

MyNewRow("number") = staffnum.Text
MyNewRow("password") = staffpassword.Text
MyNewRow("access") = "1"
MyNewRow("first name") = firstname.Text
MyNewRow("last name") = lastname.Text
MyNewRow("date of birth") = dob.Text
MyNewRow("address line 1") = address1.Text
MyNewRow("address line 2") = address2.Text
MyNewRow("town") = town.Text
MyNewRow("county") = county.Text
MyNewRow("post code") = postcode.Text

aDataTable.Rows.Add(MyNewRow)

Dim changes As Integer
Dim commandbuilder As New OleDb.OleDbCommandBuilder(oleDbStaffAdapter)
changes = oleDbStaffAdapter.Update(aDataTable)


Catch ex As InvalidOperationException
MsgBox(ex.Message)
End Try

Thanks, Rik
Dec 9 '07 #1
4 1734
Shashi Sadasivan
1,435 Expert 1GB
That errror is caused because you have not set an insert command to the adapter.

you need to set the OleDbDataAdapter.InsertCommand Property so that the adapter know how to insert a new row if it cannot find it in the database
Dec 9 '07 #2
hathan
10
I dont understand how i would do that, i have read the link to setting an insert command to the adapter but i still dont get it. Someone please help.
Dec 10 '07 #3
CyberSoftHari
487 Expert 256MB
The problem is you are not aware of sql queries. The link given is all about queries in sql which is not used in your code.

Creating DataTable
Dec 10 '07 #4
kenobewan
4,871 Expert 4TB
I note the same code is coming up multiple question and that you are basically multiposting under the guise of different questions. I also find it difficult to believe that this is a university course, although some unis will offer anything if they can find a student.

Your questions appears to be a Homework Assignment and you should make a proper attempt at assignment/program. This question will now be closed and you will have to post a new question when you're ready. I strongly recommend reading the posting guidelines.

MODERATOR
You chose to ignore the above post. The initial warning was about your assignment, now you just keep posting similiar versions of the same code. This is a warning that continuing to ignore posting guidelines will mean a temporary ban. I am now closing the post. Thanks.

MODERATOR
Dec 10 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William | last post by:
i am using a dataset and a DataAdapter to update a table with the following schema: ResourceID ProjectID LastName FirstName Year Nov Dec Jan
7
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double...
2
by: eric dugal | last post by:
Hi all!! I need your help.... i'm working since 2 hours on a simple insert statement, but couldn't handle it. Here is my code : public int ExecQuery(string SqlString) {
3
by: Neil Zanella | last post by:
Hello, I am trying to execute ADO.NET INSERT statement where one of the fields is coming from a password HTML control. When I access the text with password.Value and print with Response.Write...
3
by: Nathan Sokalski | last post by:
When trying to submit data to an Access database using ASP.NET I recieve the following error: System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41...
5
by: amitbadgi | last post by:
Hi guys, I am getting the following error in teh insert statement , I am converting this asp application to asp.net, here is teh error, Exception Details:...
2
by: RSH | last post by:
I have a rather simple script that transfers data from a SQL server database to an Access database. The procedure is intended to be dynamic so I am basically adding a datarow and then passing the...
6
by: ewpatton | last post by:
Good day, I've been trying to work with SQL and an Access database in order to handle custom user profiles. I haven't had any trouble reading from my database, but inserting new entries into...
3
by: ALaurie10 | last post by:
Hi I have code below that enables a user to browse for an excel file, import the spreadsheet data, and dump it into a table . I keep receiving 3134 syntax error for "INSERT INTO" statement. Could...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.