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.AutoGenerateColumnstotrueand check whether the datagridview fill the data or not…You can create the datagridview column by following way:
Go to properties of
datagridviewand then go to Columns Section where you can add new column in datagridview according to your datatable….MatchDataPropertyNamewith your datatable column and keepAutoGenerateColumnstofalseand then it’ll works fine…