日期:2014-05-17 浏览次数:20934 次
private void sqlexec2()
{
string str = "server=.;uid=sa;pwd=ttt;database=xxxx";//连接字符串
string sql = "select number,name,sex from mytemp where sex='男' and department='销售';select number,name,sex from mytemp where sex='女' and department='销售部';"; //两个查询语句
SqlConnection conn = new SqlConnection(str);//连接对象
SqlCommand comm = new SqlCommand(sql, conn);
DataTable dt = new DataTable();
SqlDataReader dr = null;
conn.Open();
dr = comm.ExecuteReader();
dt.Load(dr);
dataGridView1.DataSource = dt;
dr.NextResult();
dt.Load(dr);
dataGridView2.DataSource = dt;
conn.Close();
}