0

所以我有一个辅助类,其中包含以下代码:

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表格的行,我还需要它来显示这些majorFieldgradePointAverage.

我该怎么做呢?

4

1 回答 1

1

将 DataGridView 添加到您的表单并将其命名为DataGridView1,然后

private void btnStudentView_Click(object sender, EventArgs e)
{
    DataSet ds = studentHelperClass.selectStudent();
    DataGridView1.DataSource = ds.Tables["studentInfo"];

}
于 2013-09-15T12:06:51.543 回答