意图在DataGrid中新增记录并在点击"插入"按钮后更新数据库,但系统提示'Insert语法有错',看了半天也不知道错在哪里,麻烦大家帮我看看.
private void DataGridTest_Load(object sender, System.EventArgs e)
{
string strOpen="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/VisualStudio Projects/WinForm/Test.mdb";
string strQuery="select * from users";
con=new OleDbConnection(strOpen);
ada=new OleDbDataAdapter(strQuery,con);
cmd=new OleDbCommandBuilder(ada);
con.Open();
ds=new DataSet();
ada.Fill(ds);
dbg.DataSource=ds.Tables[0];
}
private void btnInsert_Click(object sender, System.EventArgs e)
{
if(ds.HasChanges())
{
try
{
ada.Update(ds);
MessageBox.Show("已插入!");
}
catch(OleDbException ex)
{
MessageBox.Show(ex.Message);
}
}
}