- SqlConnection cnn;
- //实例化sqlConnection对象
- cnn = new SqlConnection("server=192.168.0.10 ; uid = sa ; pwd = szjj1995;database=TEST_HY ;");
- //打开sql
- cnn.Open();
- //创建查询语句
- String sql = "select OID ,OrderName from OrderDetail";
- SqlCommand com = new SqlCommand(sql, cnn);
- //创建sqlDataAdapter
- SqlDataAdapter myDa = new SqlDataAdapter(com);
- //创建DataSet用来存储数据
- DataSet DS = new DataSet();
- //将数据填充到DataSet中
- myDa.Fill(DS, "OrderDetail");
- //在DataGirdView中显示
- dataGridView1.DataSource = DS;
- dataGridView1.DataMember = "OrderDetail";
- cnn.Close();
c# winform 添加dataGridView数据源
最新推荐文章于 2024-06-14 15:55:33 发布