2021年1月17日星期日

How display table from combobox

Hi i have combobox with Table names. I would like to display selected table on button click. How to do it? This is code of my combobox

Con.Open();  SqlCommand cmd = new SqlCommand("SELECT name FROM sys.tables", Con);  SqlDataReader rdr;  rdr = cmd.ExecuteReader();  DataTable dt = new DataTable();  dt.Columns.Add("name", typeof(string));  dt.Load(rdr);  wczytywanie.ValueMember = "name";  wczytywanie.DataSource = dt;  Con.Close();  

now i would like to display these tables in dataGridView after button click.This is not working.

              Con.Open();              SqlCommand cmd = new SqlCommand("SELECT * from sys.tables where name=@name", Con);              cmd.Parameters.Add("name", wczytywanie.SelectedValue.ToString());              SqlDataAdapter da = new SqlDataAdapter(cmd);              DataTable dt = new DataTable();              da.Fill(dt);              Dane.DataSource = dt;              Con.Close();  
https://stackoverflow.com/questions/65768500/how-display-table-from-combobox January 18, 2021 at 11:35AM

没有评论:

发表评论