我想用ListView 在VS上做一个学员成绩查询。但是这个控件我不熟悉,求高手给段代码。具体如下
学员信息表(stu)包含学号,姓名
学员成绩表(stucj)包含学号,成绩成绩表学号引用了信息表的学号我写了下面一段,但关键代码不知怎么写. string no ;
string name ;
string cj; string sql = string.Format("select stu.stuNo,stu.stuName,stucj.stucj from stu,stucj where stu.stuNo=stucj.stuNo",no,name,cj);
SqlCommand com = new SqlCommand(sql,DBhelper.conn);
DBhelper.conn.Open();
SqlDataReader r;
r = com.ExecuteNonQuery();
while (r.Read())
{
no = (string)r["stuNo"];
name = (string)r["stuName"];
cj =(string)r["stucj"]; ListViewItem iv = new ListViewItem(stuNo);
iv.Tag = r["stuName"];写到这就不懂了////求代码帝...
学员信息表(stu)包含学号,姓名
学员成绩表(stucj)包含学号,成绩成绩表学号引用了信息表的学号我写了下面一段,但关键代码不知怎么写. string no ;
string name ;
string cj; string sql = string.Format("select stu.stuNo,stu.stuName,stucj.stucj from stu,stucj where stu.stuNo=stucj.stuNo",no,name,cj);
SqlCommand com = new SqlCommand(sql,DBhelper.conn);
DBhelper.conn.Open();
SqlDataReader r;
r = com.ExecuteNonQuery();
while (r.Read())
{
no = (string)r["stuNo"];
name = (string)r["stuName"];
cj =(string)r["stucj"]; ListViewItem iv = new ListViewItem(stuNo);
iv.Tag = r["stuName"];写到这就不懂了////求代码帝...
string no ;
string name ;
string cj; string sql = string.Format("select stu.stuNo,stu.stuName,stucj.stucj from stu,stucj where stu.stuNo=stucj.stuNo",no,name,cj);
SqlCommand com = new SqlCommand(sql,DBhelper.conn);
DBhelper.conn.Open();
SqlDataReader r;
r = com.ExecuteNonQuery();
while (r.Read())
{
no = (string)r["stuNo"];
name = (string)r["stuName"];
cj =(string)r["stucj"];
ListViewItem iv = new ListViewItem(no);
iv.SubItems.Add(name);
iv.SubItems.Add(cj);
ListView1.Items.Add(iv);
}
ListView1.View= View.Details;
//还有不忘了给ListView1设置Columns了。。可以在属性中设置。也可以通过代码设置,如下; ColumnHeader ch = new ColumnHeader();
ch.Text = "学号";
ColumnHeader ch1 = new ColumnHeader();
ch1.Text = "姓名";
ColumnHeader ch2 = new ColumnHeader();
ch2.Text = "成绩";
listView1.Columns.Add(ch);
listView1.Columns.Add(ch1);
listView1.Columns.Add(ch2);
using......没用么??