窗体加载时,DataGridView显示绑定的sql数据
private void frmstuInfo_Load(object sender, EventArgs e)
{
string connstring = @"server=.;uid=sa;pwd=123456;database=student";
using (SqlConnection conn = new SqlConnection(connstring))
{
SqlDataAdapter da = new SqlDataAdapter("select * from stuinfo order by stuID asc",conn);
DataSet ds = new DataSet();
da.Fill(ds, "stuinfo");
this.dgvstuInfo.DataSource = ds.Tables[0].DefaultView;
}
}