将更多表列添加到列表框显示查询

时间:2013-09-15 11:36:27

标签: c# mysql

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

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

我该怎么做?

1 个答案:

答案 0 :(得分:1)

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

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

}