Yuvraj Jambhle

Yuvraj Jambhle

  • NA
  • 93
  • 8.3k

How to call Table name from combo box in sql command

Sep 26 2020 7:24 AM
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.
  1. public void getColumnName()  
  2. {  
  3. cmbFilterColumnName.Items.Clear();  
  4. SqlConnection columnCon = new SqlConnection(dbCon);  
  5. string columnQuery = @"Select Column_Name from information_Schema.Columns where Table_Name = 'Logdata'";  
  6. SqlCommand columnCmd = new SqlCommand(columnQuery, columnCon);  
  7. columnCon.Open();  
  8. SqlDataReader columnDr = columnCmd.ExecuteReader();  
  9. while (columnDr.Read())  
  10. {  
  11. string columnName = columnDr.GetString(0);  
  12. chkListBxColumnName.Items.Add(columnName);  
  13. }  
  14. columnCon.Close();  
  15. }  

Answers (2)