May I ask, my form_load, write a connection database device table code, used to achieve a startup, drop-down table combobox is connected to the device belongs to the workshop name, However, there are many duplicate values in the name of the workshop to which this column belongs. How can we remove these duplicate values and query the equipment information in the workshop by pressing the name of the workshop in the drop-down list? Related screenshots and the code of part form_load are as follows.
```c#
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
//声明一个SQLcommand对象
SqlCommand sqlcmd = new SqlCommand("SELECT * FROM b_EquipmentInfo", conn);
//执行查询语句
sda.SelectCommand = sqlcmd;
//调用DataAdapter对象的Fill()方法来填充数据集
sda.Fill(ds, "b_EquipmentInfo");
//绑定combobox的数据集
combobox1DataTable.DataSource = ds.Tables["b_EquipmentInfo"];
//选定combobox显示的成员及将Name这一列显示在combobox中
combobox1DataTable.DisplayMember = "Plinename";
//combobox的实际取值
combobox1DataTable.ValueMember = "Plinecode";
以下是点击查询按钮的代码;
```c#
conn = new SqlConnection("server=ip;database=db;user=sa;password=1123");
conn.Open();
//查询条件
SqlString = "select EquipmentCode,EquipmentName,EquipmentType,EquipmentAddress,Manufacturer,PlineName,EquipmentState from b_EquipmentInfo where PlineName = '" + combobox1DataTable.Text + "' "; //配置了与下拉列表绑定,按其查询分类显示;
//加载数据并显示
try
{
//查询条件和SqlConnection连接
SqlCommand cmd = new SqlCommand(SqlString, conn);
//数据适配器
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
//DataTable存储数据
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
catch
{ }
finally
{
conn.Close();