1.配置web.config
<appSettings>
<add key="ConnectionString" value="server=(local);uid=sa;pwd=;database=db_InformationDepartment" />
</appSettings>
2.测试数据库
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
string mysql = " select * from tb_DynamicInfo";
conn.Open();
SqlDataAdapter dap = new SqlDataAdapter(mysql, conn);
DataSet ds = new DataSet();
dap.Fill(ds);
conn.Close();
GridView1.DataSource = ds;
GridView1.DataBind();