gpt4 book ai didi

c# - mysql join查询重复返回数据

转载 作者:行者123 更新时间:2023-11-29 03:35:46 25 4
gpt4 key购买 nike

我想在 c# windows 窗体中从 mysql 数据库(使用连接查询)检索数据,但它重复给我数据 100 次。这是我的代码。请帮忙。

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

这是输出

enter image description here

最佳答案

两个表的主键都是学号吗?

关于c# - mysql join查询重复返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21901412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com