
I am facing unique problem with my code.
This is the code for showing tables in comboBox1 its working fine.
ComboBox is filled with school names and when a user select a school in that ComboBox, The students in that school will be shown in DataGridView Please help.
Functionality of this application:
- Creating a table in sql database(schoolName).
- Selecting table(select School).
- Adding values in the school(student information).
error:
- the datagrid in the bottom is not retrieving properly, its showing something else.
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + "\\Login.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM INFORMATION_SCHEMA.TABLES";
SqlDataAdapter dbAdapter = new SqlDataAdapter(cmd);
DataTable dtRecords = new DataTable();
dbAdapter.Fill(dtRecords);
dataGridView1.DataSource = dtRecords; //dataGrid
comboBox1.DataSource = dtRecords;
comboBox1.DisplayMember = "TABLE_NAME";
con.Close();