DataSet 数据集

DataAdapter 数据适配器,DataSet对象与实际数据源之间的桥梁,自动开闭数据库连接,省略Open、Close。填充数据集,需要用到Fill方法。

SQL Server数据库中表的查

using System.Data.SqlClient;//载入数据库命名空间
        public Form1()
        {
            InitializeComponent();
            //1、连接数据库
            SqlConnection con = new SqlConnection("Server=CAIWU;User Id=sa;Pwd=;DataBase=db_Me");
            SqlDataAdapter da = new SqlDataAdapter("select * from dbo.Table_2", con);//2、数据适配器
            DataSet ds = new DataSet();//3、创建数据集
            da.Fill(ds,"mySet");//4、填充数据集指定的表
            dataGridView1.DataSource = ds.Tables["mySet"];//为控件指定数据源
        }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
  • 2021-11-12
  • 2021-12-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
  • 2022-12-23
相关资源
相似解决方案