This is the code, I used for adding database tables. Its working but I want to show the added tables name in a comboBox
.
For an example: If I add a schoolName1
into the database, how can I show the schoolName1
in to comboBox
?. Thanks.
private void button1_Click(object sender, EventArgs e)
{
string myConnectionString= @"DataSource =.\SQLEXPRESS;AttachDbFileName=myconnection.mdf;Integrated Security=true;"
SqlConnection dbConnection = new SqlConnection(myConnectionString);
string myCommand = "CREATE TABLE["+textBox1.Text+"] (column1 VARCHAR(10),colunm2 INT)";
SqlCommand dbConnection = new SqlCommand(myCommand,dbConnection);
try
{
dbConnection.Open();
dbCommand.ExecuteNonQuery();
}
catch{}
dbConnection.Close();
}
To Retrieve all database tables you need to make query from information_schema.tables and bind results to desired combox
This is my way you can use several ways to retrieve this information and show in combobox reference : link
I have edited and complete your code :