也许我做错了,但我正在尝试使用 ado.net 将新行插入表中。不过,它告诉我语法是错误的。
customers = new DataTable("Customers");
cmd = "SELECT * FROM Customers";
con = new OleDbDataAdapter(cmd, strconn);
con.FillSchema(customers, SchemaType.Source);
con.Fill(customers);
DataRow cur;
cur = customers.NewRow();
cur["Company"] = textBoxCompany.Text;
cur["First Name"] = textBoxFirstName.Text;
cur["Last Name"] = textBoxLastName.Text;
cur["E-mail Address"] = textBoxEmail.Text;
cur["Job Title"] = textBoxTitle.Text;
cur["Business Phone"] = textBoxPhone.Text;
customers.Rows.Add(cur);
OleDbCommandBuilder cb = new OleDbCommandBuilder(con);
con.InsertCommand = cb.GetInsertCommand();
con.InsertCommand.Parameters.AddWithValue("Company",cur["Company"]);
con.InsertCommand.Parameters.AddWithValue("Last Name",cur["Last Name"]);
con.InsertCommand.Parameters.AddWithValue("First Name", cur["First Name"]);
con.InsertCommand.Parameters.AddWithValue("E-Mail Address",cur["E-mail Address"]);
con.InsertCommand.Parameters.AddWithValue("Job Title",cur["Job Title"]);
con.InsertCommand.Parameters.AddWithValue("Business Phone",cur["Business Phone"]);
con.Update(customers);
“INSERT INTO 语句中的语法错误。”
堆栈跟踪:
at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at Project2.Form1.button1_Click(Object sender, EventArgs e) in Form1.cs:line 54