请问一下,我的form_load里面,写了连接数据库设备表的代码,用于实现一启动,下拉表combobox即连接设备所属的车间名称,但该列所属的车间名称有很多重复值,请问怎么能去除这些个重复值呢,并实现按下拉表的车间名称,查询该车间内的设备信息,相关截图与部分form_load的代码如下;
```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();