Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
Syntax error in INSERT INTO statement ??
Administrator
Apr 6 2003 12:41 PM
2.1k
Reply
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
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
Going MAD when trying to delete from datatable.
how to return a recordset?