所以我有一个帮助类,其中包含以下代码:
public static DataSet selectStudent()
{
MySqlConnection conn = connection();
conn.Open();
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = conn;
MySqlDataAdapter adap = new MySqlDataAdapter(@"SELECT * FROM student", conn);
MySqlCommandBuilder sqlCmd = new MySqlCommandBuilder(adap);
DataSet sqlSet = new DataSet();
adap.Fill (sqlSet, "studentInfo");
conn.Close();
return sqlSet;
}
在我的表单中,我有一个显示学生数据的按钮,这是代码:
private void btnStudentView_Click(object sender, EventArgs e)
{
DataSet ds = studentHelperClass.selectStudent();
lsbBoxStudent.DataSource = ds.Tables["studentInfo"];
lsbBoxStudent.DisplayMember = "studentNumber";
}
但是,这只会显示表格的studentNumber
行,我需要它才能显示majorField
和gradePointAverage
。
我该怎么做?
答案 0 :(得分:1)
将DataGridView添加到表单并将其命名为DataGridView1
,然后将其命名为
private void btnStudentView_Click(object sender, EventArgs e)
{
DataSet ds = studentHelperClass.selectStudent();
DataGridView1.DataSource = ds.Tables["studentInfo"];
}