我想在c#窗體中從mysql數據庫中檢索數據(使用連接查詢),但它重複給我100次數據。 這是我的代碼。請幫忙。mysql連接查詢重複返回數據
private void button2_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex < 0 || comboBox2.SelectedIndex < 0)
{
MessageBox.Show("Please select the Class and group");
}
else
{
table = dbOperation.select("student.admission_no, student.studid, student.name from student inner join " +
"studentinclass on studentinclass.studentid = student.studid inner join " +
"class on studentinclass.classid = " + comboBox1.SelectedValue + " inner join " +
"`group` on studentinclass.groupid = " + comboBox2.SelectedValue + " inner join " +
"section on studentinclass.sid = " + comboBox3.SelectedValue);
listView1.Items.Clear();
foreach (DataRow row in table.Rows)
{
listView1.Items.Add(row[0].ToString());
listView1.Items[listView1.Items.Count - 1].SubItems.Add(row[1].ToString());
listView1.Items[listView1.Items.Count - 1].SubItems.Add(row[2].ToString());
listView1.Items[listView1.Items.Count - 1].SubItems.Add("P");
}
}
}
這是輸出
什麼是您所期望的輸出? BTW在Select關鍵字後添加'DISTINCT'將幫助您消除所有重複行。 – Neels
dbOperation是什麼類型? –
這是數據庫連接類的對象。 – Loyal