界面上编辑DataGridView同步更新到数据库
2008-07-09 11:22
405 查看
一。绑定数据
SqlConnection con = null; SqlDataAdapter sa = null; SqlCommandBuilder sb = null; DataTable dt = null; BindingSource bs = null; //加载窗体时绑定数据 private void DataBingding_Load(object sender, EventArgs e) { con = new SqlConnection("server=.;uid=sa;pwd=sa;database=pubs;"); try { con.Open(); sa = new SqlDataAdapter("select * from jobs", con); sb = new SqlCommandBuilder(sa);//绑定SqlDataAdapter dt = new DataTable(); sa.Fill(dt); this.dataGridView1.DataSource = dt; bs = new BindingSource(); bs.DataSource = dt;//绑定BindingSource con.Close(); } catch (Exception ex) { con.Close(); throw ex; } }
二.同步DataGridView数据到数据库
//更新 按钮单击事件 private void button1_Click(object sender, EventArgs e) { sa.Update((DataTable)bs.DataSource); }
相关文章推荐
- DataGridView编辑后立即更新到数据库的两种方法 编辑单元格
- DATAGRIDVIEW动态筛选数据,实现编辑之后,点击按钮更新,及删除选中的列到数据库。
- DataGridView编辑后立即更新到数据库的两种方法
- 容联云通讯---进微信会话界面,主动同步服务器至本地数据库
- C#用SqlCommandBuilder 更新数据库数据,解决更新数据不同步到数据库
- sql server 数据库复制实现数据同步常见问题(不定期更新)
- DataAdapter数据集DataSet和数据库的同步(3):使用CommandBuilder来更新数据集
- winform与数据库同步更新
- <续>jmeter随笔(22)将测试结果同步写入数据库更新包
- 实现ALV显示可编辑,并可更新至数据库
- 利用触发器让两台服务器上的数据库的两张表进行数据同步更新
- 用修改DataGridView数据并更新数据库
- 一个响应式数据库框架SQLBrite,完美解决数据库和UI的同步更新!
- 数据库中两张表之间的数据同步实现思路(增加、删除、更新)
- 项目中openlayer中使用,完整解决方案(数据库矢量数据,动态更新,分层,编辑)
- C# WINFORM DataGridView同步更新SQL SERVER2008 DATA
- WinForm的DataGridView焦点并没有离开该Cell无法更新数据库
- 设置DataGridView 显示自己添加编辑的列名,不动态显示数据库本身的列名
- Navicat生成更新数据库结构同步的数据库