473,396 Members | 1,849 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,396 software developers and data experts.

OledbCommand

Could Anyone help me!

I'm currenly working on an application which involves SQL
Statements. And my current problem is that when i execute
the SQL statement on MS Access 2003 the Insert Statement
performs fine when i'm using OledbCommand to execute it
there would be an exception raise "Syntax Error insert
into" Why is this so?

Here is a code segment where the error occured:

public string InsertEmployee(Employee NewEmployee)
{
DailyAttendanceConfig DAConfig = new
DailyAttendanceConfig();
DataRow DRwork;
OleDbConnection Conn;
OleDbDataAdapter OleDbAdap= new OleDbDataAdapter();
OleDbCommand Comm;
Employee Emp = new Employee();
try
{
Conn = DAConfig.MakeConnection();
DRwork = NewEmployee.Tables
[Employee.EmployeeInformationTable].Rows[0];
Comm = new OleDbCommand();
Comm.CommandText = "insert into
EmployeeInformation "
+ "(EmpID,Fname,Lname,Mname,gender,civilstatus,dateh ired,"

+"BirthDate,TinNum,SSSNum,PagIbigNum,PhilHealth,Sp ousename
,SpouseOccupation,MaidenName,Citizenship,"
+"bloodtype,telnum,cellnum,emailaddress,cityaddres s,provin
cialaddress,fathername,fatheroccupation,"
+ "mothername,motheroccupation,bankaccount,sickleave ,vacat
ionleave,active,paycode,position,"
+ "officeId,Basicpay) " +
"values (" + DRwork[0] + ",'" + DRwork[2] + "','"
+ DRwork[1] + "','" + DRwork[3] + "'," + DRwork[5] + ","
+ DRwork[4] + ",'" + DRwork[6] + "','" + DRwork[7]
+ "','" + DRwork[8] + "','" + DRwork[9] + "','" + DRwork
[10] + "','" + DRwork[11] + "','" + DRwork[12] +"','" +
DRwork[13] + "','" + DRwork[14] + "','" + DRwork[15]
+ "','" + DRwork[16] + "','" + DRwork[17] + "','" + DRwork
[18] + "','" + DRwork[19] + "','" + DRwork[20] + "','" +
DRwork[21] + "','" + DRwork[22] + "','" + DRwork[23]
+ "','" + DRwork[24] + "','" + DRwork[25] + "','" + DRwork
[26] + "'," + DRwork[28] + "," + DRwork[29] + ",1," +
DRwork[32] + ",'" + DRwork[31] + "'," + DRwork[30] + ","
+ DRwork[33] + ")";
Comm.Connection = Conn;
Conn.Open();
OleDbAdap.InsertCommand = Comm;
OleDbAdap.Update
(NewEmployee,Employee.EmployeeInformationTable);
return "Success!";
}
catch (OleDbException ex)
{
return ex.Message + " - " + ex.ErrorCode.ToString();
}
}

Please Help me on this
Nov 15 '05 #1
2 2674
set a breakpoint on line "Comm.Connection=..."
when code stops there, check out in the locals "Comm.CommandText"
copy the SQL statement and try it on a new MSAccess Query.

that way you'll find the error easier

Lennin Arriola

"Christopher" <ch***@mandaue.tti.com.ph> wrote in message
news:07****************************@phx.gbl...
Could Anyone help me!

I'm currenly working on an application which involves SQL
Statements. And my current problem is that when i execute
the SQL statement on MS Access 2003 the Insert Statement
performs fine when i'm using OledbCommand to execute it
there would be an exception raise "Syntax Error insert
into" Why is this so?

Here is a code segment where the error occured:

public string InsertEmployee(Employee NewEmployee)
{
DailyAttendanceConfig DAConfig = new
DailyAttendanceConfig();
DataRow DRwork;
OleDbConnection Conn;
OleDbDataAdapter OleDbAdap= new OleDbDataAdapter();
OleDbCommand Comm;
Employee Emp = new Employee();
try
{
Conn = DAConfig.MakeConnection();
DRwork = NewEmployee.Tables
[Employee.EmployeeInformationTable].Rows[0];
Comm = new OleDbCommand();
Comm.CommandText = "insert into
EmployeeInformation "
+ "(EmpID,Fname,Lname,Mname,gender,civilstatus,dateh ired,"

+"BirthDate,TinNum,SSSNum,PagIbigNum,PhilHealth,Sp ousename
,SpouseOccupation,MaidenName,Citizenship,"
+"bloodtype,telnum,cellnum,emailaddress,cityaddres s,provin
cialaddress,fathername,fatheroccupation,"
+ "mothername,motheroccupation,bankaccount,sickleave ,vacat
ionleave,active,paycode,position,"
+ "officeId,Basicpay) " +
"values (" + DRwork[0] + ",'" + DRwork[2] + "','"
+ DRwork[1] + "','" + DRwork[3] + "'," + DRwork[5] + ","
+ DRwork[4] + ",'" + DRwork[6] + "','" + DRwork[7]
+ "','" + DRwork[8] + "','" + DRwork[9] + "','" + DRwork
[10] + "','" + DRwork[11] + "','" + DRwork[12] +"','" +
DRwork[13] + "','" + DRwork[14] + "','" + DRwork[15]
+ "','" + DRwork[16] + "','" + DRwork[17] + "','" + DRwork
[18] + "','" + DRwork[19] + "','" + DRwork[20] + "','" +
DRwork[21] + "','" + DRwork[22] + "','" + DRwork[23]
+ "','" + DRwork[24] + "','" + DRwork[25] + "','" + DRwork
[26] + "'," + DRwork[28] + "," + DRwork[29] + ",1," +
DRwork[32] + ",'" + DRwork[31] + "'," + DRwork[30] + ","
+ DRwork[33] + ")";
Comm.Connection = Conn;
Conn.Open();
OleDbAdap.InsertCommand = Comm;
OleDbAdap.Update
(NewEmployee,Employee.EmployeeInformationTable);
return "Success!";
}
catch (OleDbException ex)
{
return ex.Message + " - " + ex.ErrorCode.ToString();
}
}

Please Help me on this

Nov 15 '05 #2
Lennin,

I already done that the SQL Statement executed well no problem was
found. i know the statement has the correct syntax. i don't know why
that error came out.

This is just the first time i had this problem since i had program with
net

Thanx

Chris
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3

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

Similar topics

2
by: Eitan | last post by:
Hello, I need sample code for using oleDBCommand in ASP (not dotnet), please. Thanks :)
1
by: Jason Steeves | last post by:
-Dim cmd As OleDbCommand -cmd = New OleDbCommand("select * from qmsstats where firstname='jason'", OleDbConnection1) -OleDbDataAdapter2.SelectCommand = cmd -DataGrid1.Visible = True...
0
by: jerim | last post by:
Hi I have the following Problem: I have an Access DB. Tablename: Formate; TableColoumns: ID (=Numeric) Name (=string)
1
by: Brian | last post by:
Was browsing around online for code to connect to a database usign ADO and C#... and i found this very simple but useful reference (http://www.c-sharpcorner.com/database/db_list.asp) However,...
2
by: Adam | last post by:
Hey guys I’m pretty new to this parameterized commands thing and I don’t know why this code isn’t working. I have a Connection object set up as Conn, and a Rec object which is holding my values....
0
by: Tom Wild | last post by:
Hi I am creating a webform in VB.Net which connects to an Access database. I can get the webform to connect to the database fine and also to download data but when I try and update the...
0
by: RG | last post by:
OleDbCommand.Prepare error: Size of parameter (VB.NET 2003) I need to do a SQL INSERT statement into an Access table, and I’d like to use the exact technique described in the Help file example...
4
by: Agnes | last post by:
Dim authConnection As New OleDbConnection("Provider = VfpOleDB.1;Data Source = d:\cgl\vfpmaster\ttsdata\tts.dbc") authConnection.Open() Dim authCommand As String = "select loginid from coinfo...
0
by: =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?= | last post by:
sippyuconn wrote: The purpose of reusing a command is to set it up with parameters and everything and then call the Prepare method. Then each time you use the command you just assign values to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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
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,...

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.