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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pravin MorePosted Nov 10, 2011, 7:40 AM
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.
TulasiPosted Nov 10, 2011, 7:35 AM
Pravin MorePosted Nov 10, 2011, 8:03 AM
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
Satishchandra TNPosted Nov 10, 2011, 7:52 AM
Satishchandra TNPosted Nov 10, 2011, 7:51 AM