我的应用程序中有一个组合框 ( comboBox1
),其中列出了我的 SQL 数据库中的类别。它目前正在正确提取数据。我唯一的问题是,当组合框中列出的数据时,有重复的结果。例如:
我希望它列出的内容:
Example 1
Example 2
Example 3
它实际上列出了什么:
Example 1
Example 1
Example 1
Example 1
Example 1
Example 2
Example 2
Example 2
Example 3
Example 3
Example 3
这是我用来列出数据的代码:
public void ListCat()
{
DataTable linkcat = new DataTable("linkcat");
using (SqlConnection sqlConn = new SqlConnection(@"Connection stuff;"))
{
using (SqlDataAdapter da = new SqlDataAdapter("SELECT name FROM list WHERE name <> 'NULL'", sqlConn))
{
da.Fill(linkcat);
}
}
foreach (DataRow da in linkcat.Rows)
{
comboBox1.Items.Add(da[0].ToString());
}
}
简而言之,我的问题是如何防止列出重复数据?