爲什麼我有這個錯誤?錯誤消息是:INSERT INTO語句中的語法錯誤。OleDbException在我的更新方法中
我想添加一條記錄到我的數據庫,但它不起作用。哪裏有問題?
的代碼是:
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbDataAdapter DbDataAdabter = new OleDbDataAdapter();
DbDataAdabter.SelectCommand = new OleDbCommand("SELECT * FROM [Phone-Book]", connection);
OleDbCommandBuilder cb = new OleDbCommandBuilder(DbDataAdabter);
connection.Open();
DataRow dataRow = myDataset.Tables["salam"].NewRow();
dataRow[1] = textBox2.Text;
dataRow[2] = textBox3.Text;
dataRow[3] = textBox4.Text;
dataRow[4] = textBox5.Text;
dataRow.EndEdit();
myDataset.Tables["salam"].Rows.Add(dataRow);
DbDataAdabter.Update(myDataset , "salam");
connection.Close();
connection.Dispose();
}
}
從dataRow [0]開始,然後重試。 –
@HansPassant:dataRow [0]是自動麻煩的! –
我必須寫這個!? –