窗体加载时,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;

            }

        }

posted @ 2012-07-02 14:12  zhcnblog  阅读(239)  评论(0编辑  收藏  举报