OleDbDataAdapter dtAdapter;
private void button15_Click(object sender, EventArgs e)
{
string con = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=STUDENT.MDB";
string sql = "select * from 考生";
OleDbConnection conn = new OleDbConnection(con);
DataTable dt = new DataTable();
dtAdapter = new OleDbDataAdapter(sql, conn);
conn.Open();
dtAdapter.Fill(dt);
this.dataGridView1.DataSource = dt;
conn.Close();
}
//将修改数据后的datagridview里数据更新到数据库,要有主键
private void button17_Click(object sender, EventArgs e)
{
try
{
DataTable dt = (DataTable)dataGridView1.DataSource;
OleDbCommandBuilder cmBuilder = new OleDbCommandBuilder(dtAdapter);
dtAdapter.Update(dt);
}
catch (OleDbException exoledb)
{
MessageBox.Show(exoledb.Message);
}
}
用修改DataGridView数据并更新数据库
最新推荐文章于 2024-10-03 09:42:26 发布