.Net Windows application using OLEDB with Access
I am trying to Insert a record in MS Access DB using OLEDB in windows application.
I am getting an error "missing semicolon at end of sql statement" there is no syntax error in sql insert statment.
My code
This is the insert statement i am using:
INSERT INTO Student
VALUES ('SRI-10-101','001','guru','30/05/2010 12:00:00 AM','','','','','','','600028','','','','','','','30/05/2010 11:25:44 AM','');
along with the code:
conn = this.GetConnection();// which returns Connection object
开发者_运维技巧tran = conn.BeginTransaction();
OleDbCommand cmd = conn.CreateCommand();
cmd.Connection = conn;
cmd.CommandText = strQuery;// Insert statement
cmd.CommandType = CommandType.Text;
cmd.Transaction = tran;
cmd.ExecuteNonQuery();
tran.Commit();
I tried with semicolon also still i get error;
Thanks
It looks like you want to set your strQuery to the value of your insert statement.
Based on your code it should look something like this:
string strQuery = "INSERT INTO Student
VALUES ('SRI-10-101','001','guru','30/05/2010 12:00:00 AM','','','','','','','600028','','','','','','','30/05/2010 11:25:44 AM','')";
As always you should verify that you are connected and defaulted to the proper database (or specify it explicitly prior to your table name (i.e. MyAwesomeDatabase.dbo.Student).
Finally it also looks like you are trying to insert a number as a character array ('001' or '600028'), if the fields in your database are of a numeric type then SQL prefers numbers without quote delimiters.
Good luck!
精彩评论