Displaying table name in the combobox
hello can anybody help me in displaying the table names from dataset into the comboBox ..
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
TulasiRank #2,544 · 549 reputationPosted Nov 10, 2011, 2:35 AM EST
Pravin MoreRank #1,419 · 1.2K reputationPosted Nov 10, 2011, 2:40 AM EST
here is code
DataSet dataSet1=new DataSet();
SqlConnection conn = new SqlConnection("Data Source='SHAWHP\\SQLEXPRESS';Initial Catalog=SoftwareInventory;Integrated Security=SSPI"); // change this coonection string according to you settings of sql server
SqlCommand cmd = new SqlCommand("SELECT name FROM Databasename.sys.tables", conn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(dataSet1, "Table");
//now you can show this dataset table on window form combobox
toolStripComboBox1.ComboBox.DataSource = dataSet1.Tables["Table"].DefaultView;
toolStripComboBox1.ComboBox.BindingContext = this.BindingContext;
Thanks,
Pravin.
Mark "Accepted Answer" if this post help you.
Satishchandra TN47 reputationPosted Nov 10, 2011, 2:51 AM EST
Satishchandra TN47 reputationPosted Nov 10, 2011, 2:52 AM EST
Pravin MoreRank #1,419 · 1.2K reputationPosted Nov 10, 2011, 3:03 AM EST
ok for that do 1 thing in 1st query of Tablename selection get tableID and Tablename too.....like this
SELECT object_id,name FROM DBName.sys.tables
so when you click on name send tableID to below Query like this
SELECT * FROM syscolumns WHERE ID=36195179 (selected objectID)
Thanks