还是关于combobox绑定数据问题~~~
privatevoidcomboBox1_SelectionChangeCommitted(objectsender,EventArgse){if(comboBox1.T...
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
{
if (comboBox1.Text == "QS**")
{
sqlClass1 = new SqlClass("select * from relatives", ConnectionType.Express);
sqlClass2 = new SqlClass("select * from relatives", ConnectionType.Express);
this.StartPosition = FormStartPosition.CenterScreen;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
sqlClass1.SqlDataAdapter.Fill(sqlClass1.DataTable);
sqlClass2.SqlDataAdapter.Fill(sqlClass2.DataTable);
bindingSource1.DataSource = sqlClass2.DataTable;
dataGridView1.DataSource = bindingSource1;
bindingSource1.DataSource = sqlClass1.DataTable;
comboBox3.DataSource = bindingSource1;
comboBox3.DisplayMember = "nowcity";//表名加字段名
comboBox3.ValueMember = "nowcity";
this.comboBox3.DataSource = sqlClass1.DataTable;//数据表
this.comboBox3.DisplayMember = "nowcity";//字段名
this.comboBox3.ValueMember = "nowcity";//字段名
comboBox4.DataSource = bindingSource1;
comboBox4.DisplayMember = "industry";//表名加字段名
comboBox4.ValueMember = "industry";
this.comboBox4.DataSource = sqlClass1.DataTable;//数据表
this.comboBox4.DisplayMember = "industry";//字段名
this.comboBox4.ValueMember = "industry";//字段名
}
这里可实现relatives表中nowcity字段和industry字段内容绑定至comboBox3和commboBox4中,可是不能去重,那去重代码要怎么写入呢? 展开
{
if (comboBox1.Text == "QS**")
{
sqlClass1 = new SqlClass("select * from relatives", ConnectionType.Express);
sqlClass2 = new SqlClass("select * from relatives", ConnectionType.Express);
this.StartPosition = FormStartPosition.CenterScreen;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
sqlClass1.SqlDataAdapter.Fill(sqlClass1.DataTable);
sqlClass2.SqlDataAdapter.Fill(sqlClass2.DataTable);
bindingSource1.DataSource = sqlClass2.DataTable;
dataGridView1.DataSource = bindingSource1;
bindingSource1.DataSource = sqlClass1.DataTable;
comboBox3.DataSource = bindingSource1;
comboBox3.DisplayMember = "nowcity";//表名加字段名
comboBox3.ValueMember = "nowcity";
this.comboBox3.DataSource = sqlClass1.DataTable;//数据表
this.comboBox3.DisplayMember = "nowcity";//字段名
this.comboBox3.ValueMember = "nowcity";//字段名
comboBox4.DataSource = bindingSource1;
comboBox4.DisplayMember = "industry";//表名加字段名
comboBox4.ValueMember = "industry";
this.comboBox4.DataSource = sqlClass1.DataTable;//数据表
this.comboBox4.DisplayMember = "industry";//字段名
this.comboBox4.ValueMember = "industry";//字段名
}
这里可实现relatives表中nowcity字段和industry字段内容绑定至comboBox3和commboBox4中,可是不能去重,那去重代码要怎么写入呢? 展开
展开全部
select distinct nowcity,industry from relatives
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询