我想将数据库中的数据显示到我的datagridview控件上
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;
}
}
}