首页| JavaScript| HTML/CSS| Matlab| PHP| Python| Java| C/C++/VC++| C#| ASP| 其他|
购买积分 购买会员 激活码充值

您现在的位置是:虫虫源码 > C# > C#使用SqlDataAdapter对象的Fill方法填充DataSet

C#使用SqlDataAdapter对象的Fill方法填充DataSet

  • 资源大小:13.50 kB
  • 上传时间:2021-06-29
  • 下载次数:0次
  • 浏览次数:0次
  • 资源积分:1积分
  • 标      签: C#源码

资 源 简 介

C#使用SqlDataAdapter对象的Fill方法填充DataSet,具体是调用DataSet的Copy方法复制DataSet中的内容,完成填充的功能:   private void Form1_Load(object sender, EventArgs e)   {    //实例化SqlConnection变量conn,连接数据库    conn = new SqlConnection("server=.;database=db_14;uid=sa;pwd=");    //创建一个SqlCommand对象    SqlCommand cmd = new SqlCommand("select * from tb_test", conn);    SqlDataAdapter sda = new SqlDataAdapter();//创建一个SqlDataAdapter对象    //设置SqlDataAdapter对象的SelectCommand属性,设置执行的SQL语句    sda.SelectCommand = cmd;    ds = new DataSet(); //实例化DataSet    sda.Fill(ds, "test");//使用SqlDataAdapter对象的Fill方法填充DataSet    dataGridView1.DataSource = ds.Tables[0];//设置dataGridView1的数据源   }   private void button1_Click(object sender, EventArgs e)   {    DataSet ds1 = ds.Copy();//调用DataSet的Copy方法复制ds中的内容    dataGridView2.DataSource = ds1.Tables[0];//将ds1作为dataGridView2的数据源   }
VIP VIP
0.169255s