C# 为什么我的选择与dataGrid重复?

C# 为什么我的选择与dataGrid重复?,c#,mysql,C#,Mysql,和按钮: public static DataSet selectStudent() { MySqlConnection conn = connection(); conn.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; MySqlDataAdapter adap = new MySqlDataAdapter(@"SELECT person.

和按钮:

 public static DataSet selectStudent()
 {
      MySqlConnection conn = connection();
      conn.Open();
      MySqlCommand cmd = new MySqlCommand();
      cmd.Connection = conn;
      MySqlDataAdapter adap = new MySqlDataAdapter(@"SELECT person.*, student.gradePointAverage, student.majorField FROM person JOIN student", conn);
      MySqlCommandBuilder sqlCmd = new MySqlCommandBuilder(adap);
      DataSet sqlSet = new DataSet();
      adap.Fill (sqlSet, "studentInfo");
      conn.Close();
      return sqlSet;
 }
为什么点击按钮会得到这样的结果


您的查询生成笛卡尔积,因为您未能定义记录之间的关联方式。您需要添加一个条件

 private void btnAdminStudentView_Click(object sender, EventArgs e)
 {
    DataSet ds = studentHelperClass.selectStudent();
    dataGridStudent.DataSource = ds.Tables["studentInfo"];
 }
这意味着来自表
person
的记录与表
student
上的
ID
相关

要进一步了解有关联接的更多信息,请访问以下链接:


可能是由于加入条件(或缺乏)的原因,谢谢,这是有效的。我将在10分钟内给出正确答案。
SELECT person.*, student.gradePointAverage, student.majorField 
FROM person JOIN student
     ON person.ID = student.ID  // example only