Reputation: 73
SqlConnection con = new SqlConnection("Data Source=MOSTAFA;Initial Catalog=mohasba;Integrated Security=True");
SqlDataAdapter SDA = new SqlDataAdapter("select * from قيد_اليوميه where رقم_القيد='" + textBox1.Text + "'", con);
con.Open();
DataTable DT = new DataTable();
SDA.Fill(DT);
dataGridView1.DataSource = SDA;
When I run this code the the datagridview appear Empty
Upvotes: 1
Views: 3915
Reputation: 116
Change the DataSource to DT
.
This:
dataGridView1.DataSource = SDA;
To This:
dataGridView1.DataSource = DT;
Upvotes: 0
Reputation: 43
you missed the dataGridView.dataBind(); this will Bind your data with the control
dataGridView1.DataSource = SDA;
dataGridView1.dataBind();
Upvotes: 0
Reputation: 7042
Make sure the DataGridView has automatic column generation property set. If the datagridview is set to manual generation of column, it won't display the data. You have to map the columns to the sql column manually.
Upvotes: 0
Reputation: 412
If there's no error message, and the datagrid is empty, it's very likely in your SQL. Have you tried running it directly? Does it return results?
If that works, doublecheck the value of textbox1.
Upvotes: 1