I want to pool table name from the combo box in the SQL query. Below code, I use a static table name as "Logdata". For your reference, I attach the code.
Please guide me on how to call the selected table in the SQL query from the combo box.
Actually, I want to write the column name of the selected table in notepad.
- public void getColumnName()
- {
- cmbFilterColumnName.Items.Clear();
- SqlConnection columnCon = new SqlConnection(dbCon);
- string columnQuery = @"Select Column_Name from information_Schema.Columns where Table_Name = 'Logdata'";
- SqlCommand columnCmd = new SqlCommand(columnQuery, columnCon);
- columnCon.Open();
- SqlDataReader columnDr = columnCmd.ExecuteReader();
- while (columnDr.Read())
- {
- string columnName = columnDr.GetString(0);
- chkListBxColumnName.Items.Add(columnName);
- }
- columnCon.Close();
- }