Hi Guys,
I am trying to list the name of all tables which belong to a selected database from the comboBox1(which is populated from SQL Server 2008).I used the following code but it seems it is just adding all System Tables! to listBox1 instead of choosing tables from selected database.
Could you please let me know how I can correct the code in order to list all tables from the selected item(Database), listed in comboBox1?
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
OleDbConnection cn = new OleDbConnection(@"provider = sqloledb; data source = .\WorkShop; integrated security = sspi;");
cn.Open();
DataTable MyTable;
MyTable = cn.GetSchema(System.Data.SqlClient.SqlClientMetaDataCollectionNames.Tables.ToString());
for (int i = 0; i < MyTable.Rows.Count; i++)
{
listBox1.Items.Add(MyTable.Rows[i].ItemArray[2].ToString());
}
}
Thanks