TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Administrator
Tech Writer
2.2k
1.5m
Syntax error in INSERT INTO statement ??
Apr 6 2003 12:41 PM
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
Reply
Answers (
2
)
Going MAD when trying to delete from datatable.
how to return a recordset?