在combobox2中显示属于combobox1的内容

在combobox2中显示属于combobox1的内容

本文介绍了如何制作,在combobox2中显示属于combobox1的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有两个数据库表:

hello, i have two database tables:

Resursai

id

resursas

 

Kop_failai

id

resursas

失败

Nauji


 button3.Enabled = false;
      string serv = "Data Source=HPDL580;Initial Catalog=metaDB;Integrated Security=True";
      SqlConnection connection = new SqlConnection(serv);
      connection.Open();
      SqlDataAdapter resursai = new SqlDataAdapter("SELECT * FROM Resursai ", connection);
      DataTable resTable = new DataTable();
      resursai.Fill(resTable);
      for (int i = 0; i < resTable.Rows.Count; i++)
      {
         comboBox1.Items.Add(resTable.Rows[i]["Resursas"]);
      }

推荐答案

string serv = "Data Source=HPDL580;Initial Catalog=metaDB;Integrated Security=True";
SqlConnection connection = new SqlConnection(serv);
connection.Open();
SqlDataAdapter resursai = new SqlDataAdapter("SELECT * FROM Resursai ", connection);
DataTable resTable = new DataTable();
resursai.Fill(resTable);

SqlDataAdapter failai = new SqlDataAdapter("SELECT * FROM Kop_failai WHERE (Nauji IS NULL) ", connection);
DataTable failaiTable = new DataTable();
failai.Fill(failaiTable);


//Add the tables to a dataset
DataSet ds = new DataSet();
ds.Tables.Add(resTable);
ds.Tables.Add(failaiTable);
//Create a relation
ds.Relations.Add("relation", resTable.Columns["ID"], failaiTable.Columns["Resursas"]);
comboBox1.DataSource = resTable;
comboBox1.DisplayMember = "Resursas";
comboBox2.DataSource = resTable;
//Use the relation
comboBox2.DisplayMember = "relation.Failas";


这篇关于如何制作,在combobox2中显示属于combobox1的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 19:55