刷新vb.net更新后的数据网格视图 [英] refresh data grid view after updating in vb.net
本文介绍了刷新vb.net更新后的数据网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
cmd.CommandText =update emp_tbl set sal ='& SalTextBox.Text& 'where id ='& id& '
表名: emp_tbl
/ p>
datagridview: emp_tbldatagridview
更新按钮: p>
cn.Open()
cmd.CommandText =更新emp_tbl set sal ='& SalTextBox.Text& 'where id ='& id& '
cmd.ExecuteNonQuery()
cn.Close()
解决方案
您必须重新绑定:
BindingSource binding = new BindingSource(); // req通过win form
DataTable dt = new DataTable();
dt.Load(sql_command.ExecuteReader());
dgv.DataSource = dt;
这是我在win窗体中找到的最好的方法.update不工作,因为它需要从SQL实际重新拉取数据。
i have a data grid view and details for a particular table.i update the details, But it doesn't get updated in the data grid view?my update statement works properly because, once i exit the project, it gets updated.
cmd.CommandText = "update emp_tbl set sal= '" & SalTextBox.Text & "' where id='" & id & "'"
table name: emp_tbl
datagridview: emp_tbldatagridview
update button :
cn.Open()
cmd.CommandText = "update emp_tbl set sal= '" & SalTextBox.Text & "' where id='" & id & "'"
cmd.ExecuteNonQuery()
cn.Close()
解决方案
You have to re-bind it:
BindingSource binding = new BindingSource(); //req. by win forms
DataTable dt = new DataTable();
dt.Load(sql_command.ExecuteReader());
dgv.DataSource = dt;
This is the best way I've found to do it in win forms, .update doesn't work because it needs to actually re-pull the data from SQL.
这篇关于刷新vb.net更新后的数据网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文