473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting Syntax Error in INSERT INTO Statement (C# - MS Access)

2 New Member
if (comboBox1.Enabled == true && textBox5.Text != "")
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source= c:\users\mert\" + @"documents\visual studio 2010\Projects\PayrollCS\WindowsFormsApplication7\P ayrollDB.accdb";
con.Open();
OleDbCommand cmdole1 = new OleDbCommand("SELECT SalaryHead_ID FROM SalaryHead WHERE SalaryHead = '" + comboBox1.Text +"' " , con);
int salaryheadid = (int)cmdole1.ExecuteScalar();
OleDbCommand cmdole = new OleDbCommand("INSERT INTO [GroupContains](SalaryGroup_ID,SalaryHead_ID) Values ('"+textBox5.Text +"' , '"+ salaryheadid.ToString()+"') ", con);
cmdole.ExecuteNonQuery();
try
{

OleDbCommand cmdole2 = new OleDbCommand("INSERT INTO [SalaryCardHead](SalaryHead_ID,SalaryGroupID,Value) Values ('"+salaryheadid.ToString()+"','"+textBox5.Text+"' , '"+ textBox4.Text+"') ", con);
cmdole2.ExecuteNonQuery();
}
catch (OleDbException err)
{
MessageBox.Show(err.ToString());
}

this is my code. I am getting this error on "cmdole2" query.

error text is:

---------------------------

---------------------------
System.Data.OleDb.OleDbException (0x80040E14): Syntax error in INSERT INTO statement.

at System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(OleDbHResult hr)

at System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult)

at System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult)

at System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult)

at System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method)

at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()

at WindowsFormsApplication7.SalaryGroup.SalaryGroup.t oolStripButton8_Click(Object sender, EventArgs e) in C:\Users\MERT\documents\visual studio 2010\Projects\PayrollCS\WindowsFormsApplication7\S alaryGroup\SalaryGroup.cs:line 306
---------------------------
OK
---------------------------
Apr 6 '12 #1
1 7447
mertsenel
2 New Member
I've found the problem. Column name Value is a reserved word for Access so it gives error. Changed the coloumn name and solved.
Apr 6 '12 #2

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

Similar topics

2
12946
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...
3
1614
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...
2
9278
by: Roy Rodsson via .NET 247 | last post by:
Hi all! I am using a stored procedure in SQL2000 for retrieving fileinformations from a db. the table as an uniqueidentifier for the file information. The stored procedure has a variable...
1
2187
by: tw | last post by:
Scenario: Error: Microsoft JET Database Engine (0x80004005) Operation must use an updateable query. I have xp professional with iis6. the folder is under wwwroot with asp file and mdb file....
18
3759
by: rahuls | last post by:
Hi everyone, I have a couple of questions? 1.this is part of my main function ////////////////////////////// int main() { FILE *f1; int i,j; j=100000000; int intData;
1
1328
by: ucbu | last post by:
Hi, I wrote an ASP page using MS access 2000 on an ISS 5.0. I got "Microsoft JET Database Engine (0x80040E14) Syntax error in INSERT INTO statement." at the execute line of the sql: insert...
7
2831
by: Yesurbius | last post by:
I am receiving the following error when attempting to run my query. In my mind - this error should not be happening - its a straight-forward query with a subquery. I am using Access 2003 with all...
0
2317
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...
0
1421
by: dougancil | last post by:
I have the following code: Imports System.Data.SqlClient Public Class Main Protected WithEvents DataGridView1 As DataGridView Dim instForm2 As New Exceptions Private Sub...
0
7199
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,...
0
7076
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...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6984
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...
0
7453
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...
0
5576
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,...
0
4670
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...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
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...

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.