在 VS中对于数据库增删查改的操作 那篇文章
this.studentTableAdapter.Fill(this.schoolDataSet.Student);//使其显示更新后的表
博主我这里studentTableAdapter和schoolDataSet报错
我觉得是数据库的名字不一样,
我想问问您当时这个是数据库的名字还是
你直接复制网上代码的吗?
数据库要是自己本地数据库的配置。
private void button_delete_Click(object sender, EventArgs e)
{
try
{
con.Open();
string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//选择的当前行第一列的值,也就是ID
string delete_by_id = "delete from Student where Sno=" + "'"+select_id+"'";//sql删除语句,根据学号删除
SqlCommand cmd = new SqlCommand(delete_by_id, con);
cmd.ExecuteNonQuery(); //执行命令
}
catch
{
MessageBox.Show("请正确选择行!","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
con.Dispose();
}
this.studentTableAdapter.Fill(this.schoolDataSet.Student);//使其显示更新后的表
}