田贤追博客 - QQ:260776893,Tel:13065860667

网站建设电子商务博客(网站制作,优化推广,网络营销宣传,B2B,网络广告),网络维护,平面设计及相关的文章信息发布共享。

« C#编写的Unicode文本空行去除器站在蜘蛛角度来看网页 »

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

最近用到数据库,发现C#2005默认没有DataGrid,如果需要可以自己添加。并且提供了一个更新的DataGridView。但两者操作上还是有一些区别的。找了半天才找到一些处理数据的方法。具体做法就不说了,仅列出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);
            }
         }
 

  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Walle Build 91204

© 2007-2009 Powered By 田贤追博客 All rights reserved. 浙ICP备09005319号·