62,041
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
string str = "Server=localhost;DataBase=Norwind;UID=sa;PWD=**";
SqlConnection mycon = new SqlConnection(str);
mycon.Open();
}
private static string strsql;
SqlConnection con = new SqlConnection("server=localhost;database=fireplaces;uid=sa;pwd=sa");//这个是全局变量
private void Databind(string strsql)
{
SqlCommand sqlcom = new SqlCommand(strsql, con);
con.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = sqlcom;
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
strsql = "select * from stone_storage";//你的查询语句
Databind(strsql);
}