关闭

DataGridView填充、更新、删除(多行)Sql Express 2005数据库

825人阅读 评论(0) 收藏 举报
 WinForm下DataGridView填充、更新、删除(多)Sql Express 2005数据库代码。
        private void button1_Click(object sender, EventArgs e)
        {
            this.hostTableAdapter.Fill(this.hostScanDataSet.host);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.hostTableAdapter.Update(this.hostScanDataSet.host);
            MessageBox.Show("记录已保存!");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult dlResult = MessageBox.Show(this, "要删除这些记录吗?", "请确认",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button1,
                MessageBoxOptions.RightAlign);
            if (dlResult == DialogResult.Yes)
            {
                int j = dataGridView1.SelectedRows.Count;
                int[] l = new int[j];

                int i;
                for (i = 0; i < j; i++)
                {
                    l[i] = dataGridView1.SelectedRows[i].Index;
                }

                int k = 0;
                while (k < j)
                {
                    this.hostScanDataSet.host.Rows[l[k]].Delete();
                    k++;
                }
                this.hostTableAdapter.Update(this.hostScanDataSet.host);
            }
         }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:393169次
    • 积分:7245
    • 等级:
    • 排名:第3193名
    • 原创:325篇
    • 转载:71篇
    • 译文:1篇
    • 评论:34条
    最新评论