111,119
社区成员
发帖
与我相关
我的任务
分享
using System.Data;
using System.Data.SqlClient;
//读库,绑定
//col1 col2 col3
//1 2 3
//则可用 sql = "select col2 from A";
//col1 col2 col3
// 1 aa aaaa
// 2 bb bbbb
// 3 cc cccc
//则可用 sql = "select * from A where col1=2";
//假设为第二种情况
string connStr = "server=.;uid=sa;pwd=;database=myDB"; //myDB为数据库名
SqlConnection conn = new SqlConnection(connStr);
string sql = "select * from A where col1=2";
SqlDataAdapter adp = new SqlDataAdapter(sql,conn);
DataTable dt = new DataTable();
adp.Fill(dt);
this.DataGridView1.DataSource = dt.DefaultView;