i want to show the data from the database onto my datagridview control i have used the following piece of code but it is not showing any data when the form loads it just shows and empty datagridview i don't get any errors what am I doing wrong
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.AutoGenerateColumns = false;
FillData();
}
public void FillData()
{
using (SqlConnection myConnection = new SqlConnection("server=localhost;" +
"Trusted_Connection=yes;" +
"database=database; " +
"connection timeout=10"))
{
myConnection.Open();
using (SqlDataAdapter sqlDa = new SqlDataAdapter("select * from スコープ", myConnection))
{
DataTable dt = new DataTable();
sqlDa.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
I suspect there is no matching column of datatable with datagridview column....Check the column of datagridview with datatable column....
For test, make dataGridView1.AutoGenerateColumns to true and check whether the datagridview fill the data or not...
dataGridView1.AutoGenerateColumns= true;
You can create the datagridview column by following way:
Go to properties of datagridview and then go to Columns Section where you can add new column in datagridview according to your datatable....Match DataPropertyName with your datatable column and keep AutoGenerateColumns to false and then it'll works fine...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With