能不能把接收的数据先存入DataRow数组里,在显示在列里

来源:百度知道 编辑:UC知道 时间:2024/06/09 09:56:11

5月22日 19:27 if(!Page.IsPostBack)
{
SqlCommand com=new SqlCommand("select distinct Course_name from scoreview",con);
con.Open();
SqlDataReader dr=com.ExecuteReader();
DataTable tab=new DataTable();
tab.Columns.Add(new DataColumn("学号",typeof(string)));
tab.Columns.Add(new DataColumn("姓名",typeof(string)));
while(dr.Read())
{this.Label1.Text=dr[0].ToString();
tab.Columns.Add(new DataColumn(dr[0].ToString(),typeof(string)));
}
con.Close();

SqlCommand sqlcom=new SqlCommand("select distinct Student_no,Student_name from scoreview",con);
con.Open();
SqlDataReader sdr=sqlcom.ExecuteReader();
DataRow drow;
while(sdr.Read())
drow=tab.NewRow();
for(int i=0;i<2;i++)
{
drow[i]=sdr[i].ToString();
}
tab.Rows.Add(drow);
}
con.Close();

SqlCommand cnu=new SqlCommand("select count(distinct Course_name),count(*) from