OledbCommand

  • Thread starter Thread starter Christopher
  • Start date Start date
C

Christopher

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,datehired,"

+"BirthDate,TinNum,SSSNum,PagIbigNum,PhilHealth,Spousename
,SpouseOccupation,MaidenName,Citizenship,"
+"bloodtype,telnum,cellnum,emailaddress,cityaddress,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
 
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
 
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
 
Back
Top