Syntax error in INSERT INTO statement ??
I'm having problem while trying to insert a record into Access database. I tried using 2 different methods to insert the record, but receiving same error message. Please help to check if there's any problem with the following codes:
--- Start Code #1 ---
OleDbTransaction DBTrans;
OleDbConnection DBConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/Customers.mdb");
OleDbCommand DBCommand = new OleDbCommand("INSERT INTO Customers (UserID, Password, UserLevel) VALUES ('leth', 'leth', 'leth');", DBConn);
DBConn.Open();
DBTrans = DBConn.BeginTransaction();
DBCommand.CommandType = CommandType.Text;
DBCommand.Transaction = DBTrans;
DBCommand.ExecuteNonQuery();
DBTrans.Commit();
DBConn.Close();
--- End Code #1 ---
--- Start Code #2 ---
OleDbConnection DBConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/Customers.mdb");
OleDbCommand DBCommand = new OleDbCommand(SQLstr, DBConn);
OleDbDataAdapter DBAdapter = new OleDbDataAdapter(DBCommand);
OleDbCommandBuilder DBBuilder = new OleDbCommandBuilder(DBAdapter);
DBConn.Open();
try
{
DBAdapter.Fill (Result, TableName);
DataRow dr;
dr = Result.Tables["Customers"].NewRow();
dr[0] = "leth";
dr[1] = "abc";
dr[2] = "z";
Result.Tables["Customers"].Rows.Add(dr);
DBAdapter.Update(Result,"Customers");
}
finally
{
DBConn.Close();
}
--- End Code #2 ---
Thank you very much!!!
Lethain