473,787 Members | 2,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Syntax error in insert into statement

7 New Member
Hello...
i am doing some kind of application using Vb.net connected to an access database..unfor tunately i am getting this SYNTAX ERROR IN INSERT INTO STATEMENT...i have been trying to find out y for a day now but i really can't find answers...im feeling sorry for myself now..i am jst a beginner...coul d someone out there pls help me with this..i so much thank you in advance...
here is my simple code...

Dim command as New Oledbcommand

With command
.Connection = myconnection
.CommandText = "INSERT INTO tblemployee(Fna me,Mname,Lname, Position,Gender ,Cstatus,Bday,A ge,Address,Tele phone,Cellphone ,Emailaddress,S oftwareknowledg e) VALUES('" & txtFname.Text & "','" & txtmname.Text & "','" & txtLname.Text & "','" & cmbposition.Tex t & "','" & cmbgender.Text & "','" & cmbcstatus.Text & "','" & txtbday.Text & "','" & txtage.Text & "','" & txthome.Text & "','" & txttelephone.Te xt & "','" & txtcp.Text & "','" & txtEmail.Text & "','" & txtswk.Text & "')"
.ExecuteNonQuer y()
End With
Sep 10 '11 #1
6 5632
Gwenne Moses
7 New Member
oohh thank u for all those who viewed my Query...
my program works now...finally found out y...
tnx much...
Sep 10 '11 #2
kamellion
2 New Member
Gwenne, consider posting your solution. Others may learn from this, also a solution makes the post complete.

Regards
Sep 10 '11 #3
yarbrough40
320 Contributor
Using inline values for insert statements like you are doing here can be dangerous (just fyi). If you are unfamiliar, read up on "sql injection" attacks. Both oledb and sqlconnection methods have parameterized insert options that willwork for your purposes and are much safer.

Happy coding!
Sep 10 '11 #4
Gwenne Moses
7 New Member
Okay...
i jst tried putting brackets [] in my field names n table name..it did work...

oohh yes..i will..thank u so much!
Sep 10 '11 #5
yarbrough40
320 Contributor
Can you show examples of what you're trying to do?
Sep 10 '11 #6
Gwenne Moses
7 New Member
i have a form that is full of textboxes where in the user have to input details or personal info of an employee ..those inputted details r to be saved to an access database...the user should also be able to update n delete records...
i solved my aforementioned problem by putting brackets with my table name n field names too...this is how i did it...
"INSERT INTO [tblemployee]([Fname],[Mname],[Lname],[Position],[Gender],[Cstatus],[Bday],[Age],[Address],[Telephone],[Cellphone],[Emailaddress],[Softwareknowled ge]) VALUES('" .........etc... .

i did put brackets in my update statement too...
now my whole program works flawlessly...
tnk u!
Sep 11 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
6675
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
12961
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error from the code below! Error: INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_tblOfficePageContent_tblPageContent'. The conflict occurred in database 'CPNCMS', table 'tblPageContent', column 'pageID'. The statement has been terminated. I cant seem to see why I keep getting an error when I do the insert!
3
1632
by: jinhy82 | last post by:
Hi! I am currently creating a Registration form which contained: UserID Password, FirstName and LastName. These details would be inserted into Ms Access when I click submi button. But I encounter with the problem to insert 'Password'. It work fine if I did not insert 'Password' but if I did, it will shows that have "syntax error: INSERT INTO..." Did I miss something to write? Please kindly have a look on the cod below, Thank you!
3
2501
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
3211
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request : INSERT INTO temp_tab VALUES (1,2,3)
1
1413
by: vasanth chandrasekaran | last post by:
The error is :Syntax error in INSERT INTO statement. This is my code: try { DataSet ds1; OleDbConnection ConnSql; OleDbConnection ConnExcel; OleDbDataAdapter da1; OleDbDataAdapter da2; string ConnStringSql = "Provider=sqloledb;Data Source = cst;Initial Catalog = Testido;User ID=sa;Pwd=connect#963;";
9
2770
by: Ed Pisa | last post by:
Hello, I have been working with this problem now for several days. I can delete and Update my data but I can not get it to insert a new record. I receive the syntax error insert into. I am not using any reserved words and I have not been able to find my answer googling like crazy. Any help would be greatly appreciated. below is the code that seems to give me the problem. ElseIf NEWMODE = True Then Dim oAdapter As...
0
2350
by: Ed Pisa | last post by:
Hello, I have been working with this problem now for several days. I can delete and Update my data but I can not get it to insert a new record. I receive the syntax error insert into. I am not using any reserved words and I have not been able to find my answer googling like crazy. Any help would be greatly appreciated. below is the code that seems to give me the problem. ElseIf NEWMODE = True Then Dim oAdapter As...
0
9497
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
10110
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
8993
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...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
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
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
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
2894
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.