I'm having a bit of a problem when trying to populate cascading comboboxes. First part works great, the forst combobox gets filled. Here is the code:
private void LoadCombo()
{
try
{
SqlConnection conn = new SqlConnection(@"Data source=SERVERSOURCE;Initial Catalog=MyDatabase; Integrated security=true;");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("select name from sys.tables where type = 'U'", conn);
DataTable dt = new DataTable();
foreach (DataRow row in dt.Rows)
{
comboBox1.Items.Add(row["name"].ToString());
}
}
catch (Exception ex)
{
throw ex;
}
}
Now, all table names are loaded in comboBox1. Now, here's the main problem: I'm trying to retrieve table name from comboBox1 and use the text to pass another query to Sql server, so that, when I make a selection in comboBox 1, comboBox 2 gets filled with table properties of a specified column of a called table. Here is the code:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(@"Data source=SERVERSOURCE;Initial Catalog=MyDatabase; Integrated security=true;");
SqlDataAdapter da = new SqlDataAdapter("select distinct CollumnName from'"+ comboBox1.Text +"'", conn);
DataTable dt = new DataTable();
da.Fill(dt);
foreach (DataRow row in dt.Rows)
{
comboBox2.Items.Add(row["CollumnName"].ToString());
}
}
catch (Exception ex)
{
throw ex;
}
}
I've been geting "syntax error near CollumnName". How do I fix this problem? Thank you!