Why is my SELECT repeated with dataGrid?

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; } 

and button:

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

why would it give me a result similar to this when a button is clicked?

enter image description here

+4
source share
1 answer

Your query produces Cartesian products because you were unable to determine how the records relate to each other. You need to add a condition

 SELECT person.*, student.gradePointAverage, student.majorField FROM person JOIN student ON person.ID = student.ID // example only 

this means that the entries in the person table are associated with the ID in the student table.

To learn more about unions, click on the link below:

+6
source

Source: https://habr.com/ru/post/1502405/


All Articles