473,785 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB 2003.net Syntax error in INSERT INTO statement

10 New Member
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.Ole Db.OleDbExcepti on: Syntax error in INSERT INTO statement.
at System.Data.Com mon.DbDataAdapt er.Update(DataR ow[] dataRows, DataTableMappin g tableMapping)
at System.Data.Com mon.DbDataAdapt er.Update(DataT able dataTable)
at movie_rentals.e mployeeadd.Butt on2_Click(Objec t sender, EventArgs e) in C:\Users\Rik\De sktop\Riks work\VB\picture s for vb\DVDs r us\Employee Add.vb:line 409
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


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

Dim connStr As String = "Provider = Microsoft.Jet.O LEDB.4.0;" & _
"Data Source = dvd.mdb"
Dim aDataTable As New DataTable
Dim squlStr As String = "SELECT * From Users"
Dim oleDbStaffAdapt er As New OleDb.OleDbData Adapter(squlStr , connStr)

aDataTable.Clea r()

oleDbStaffAdapt er.Fill(aDataTa ble)
Dim MyNewRow As DataRow = aDataTable.NewR ow

MyNewRow("numbe r") = staffnum.Text
MyNewRow("passw ord") = staffpassword.T ext
MyNewRow("acces s") = "1"
MyNewRow("first name") = firstname.Text
MyNewRow("last name") = lastname.Text
MyNewRow("date of birth") = dob.Text
MyNewRow("addre ss line 1") = address1.Text
MyNewRow("addre ss line 2") = address2.Text
MyNewRow("town" ) = town.Text
MyNewRow("count y") = county.Text
MyNewRow("post code") = postcode.Text

aDataTable.Rows .Add(MyNewRow)

Dim changes As Integer
Dim commandbuilder As New OleDb.OleDbComm andBuilder(oleD bStaffAdapter)
changes = oleDbStaffAdapt er.Update(aData Table)


Catch ex As InvalidOperatio nException
MsgBox(ex.Messa ge)
End Try

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

you need to set the OleDbDataAdapte r.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 New Member
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 Recognized Expert Contributor
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 Recognized Expert Specialist
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
4774
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
6672
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 checked, and the insert works fine (tried to use it from access)... im using visual C# express 2k5... what could be wrong? thanks!
2
1603
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
2823
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 so as to check that it is working correctly it displays just fine. However, whenever I include the password field in one of the SQL INSERT statement's fields I get the following error:
3
2500
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 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
5
2145
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: System.Runtime.InteropServices.COMException: Syntax error in INSERT INTO statement. Source Error: Line 118: MM_editCmd.ActiveConnection = MM_editConnection
2
2813
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 data with a simple loop. I am using OleDbCommandbuilder to build the INSERT command but for some reason when it gets to a particular table in the database it errors out giving me "Syntax Error in INSERT INTO Statement". The cmmandbuilder built...
6
6005
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 it has been troublesome to say the least. My ASP.NET script is supposed to execute an INSERT INTO statement in order to add a user to the database. Here is a sample:
3
2391
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 someone please help me out? Also when I copy and paste this code into a module in a new database, I get an error message for the "Dim dlgPickFiles As Office.FileDialog" statement. I didn't get this error message in the old database, and don't...
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.