C#中datagriad直接写代码而不用控件连接的删除,修改,刷新等操作
为什么写的删除代码删掉当前行时并没有直观显示已经删掉该行而是刷新后才显示?
代码如下:
private void button删除_Click(object sender, EventArgs e)
{
scon = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=超市管理系统;Data Source=localhost";
SqlConnection con = new SqlConnection(scon);
string select_str="select * from 用户表";
SqlDataAdapter da = new SqlDataAdapter(str,con);
SqlCommandBuilder scb = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds,"用户表");
if (this.dataGridView1.Rows.Count > 0)
{
ds.Tables["用户表"].Rows[this.dataGridView1.CurrentRow.Index].Delete();
da.Update(ds ,"用户表");
MessageBox.Show("删除成功");
}
else
MessageBox.Show("没有可以删除的行了!");
} }