Winform中DataGridView多行删除
来源:互联网 发布:hwmonitor mac 编辑:程序博客网 时间:2024/05/22 11:54
//在DataGridView中删除选中行,从数据库中删除。private void ButtonDelete_Click(object sender, EventArgs e){ if (dataGridView1.DataSource == null || dataGridView1.CurrentRow == null) { return; } else { if (this.dataGridView1.SelectedRows.Count > 0) { DialogResult dr = MessageBox.Show("确定删除选中的记录? ", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { try { dbcon.Open(); //打開連接 string sql = ""; OracleCommand cmd = dbcon.CreateCommand(); //遍历所选中的dataGridView记录行 foreach (DataGridViewRow row in this.dataGridView1.SelectedRows) { //取dataGridView1中的第三列的值 string strName = row.Cells[2].Value.ToString(); sql = "delete from company where name='" + strName + "'"; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = sql; cmd.ExecuteNonQuery(); //执行删除 } cmd.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "提示"); } finally { dbcon.Close(); //關閉連接 dbcon = null; //釋放資源 } //删除后执行刷新操作 this.ButtonFresh_Click(null, null); } else { return; } } }}
- Winform中DataGridView多行删除
- C#Winform删除DataGridView中被选中的行
- Winform中DataGridView的删除功能
- Winform DataGridView 删除、修改
- Winform 批量删除DataGridView
- WinForm中DataGridView控件通过复选框实现多条记录的删除 c#2005
- C# WinForm中DataGridView的修改删除功能
- Winform中DataGridView有自动添加行!
- winform中datagridview显示合计行
- DataGridView删除多行
- .NET Winform Datagridview 实现多行表头
- winform程序中DataGridView、DataGridViewComboBoxCell
- WinForm中手动绑定DataGridView
- Winform中datagridview控件使用
- DataGridView同时删除多行
- WinForm 中DataGridView不显示最后空白的行
- winForm中让DataGridView显示行号,去除空记录行
- Winform下DataGridView 一个单元格中实现多个超链接
- 密码中有特殊字符,如何登录SQLPLUS
- 概率问题:星期二出生的孩子
- 关于替换wince 自带界面(Shell)的问题
- FTP命令学习
- solr搭建中的问题
- Winform中DataGridView多行删除
- Apache Ant
- Windows Phone 7 取消注册
- Java连接各种数据库的实例
- C++中NEW的三种用法
- 给C++初学者的50个忠告(转载)
- 世界上最健康的作息时间表
- 每天读一遍
- js调用cookie