新手学东西
string str = "user id=sa;password=000;initial catalog=glxtSQL;Server=KEYJOB;Connect Timeout=60; ";
SqlConnection conn = new SqlConnection(str);
conn.Open();
在.cs页面写一个数据库连接类
之后在页面怎么掉用
帮忙写下
马上散分
------解决方案--------------------跟普通类一样调用呀
------解决方案--------------------实例化一个类的对象,然后把con当参数传达室给查询方法
------解决方案--------------------Connnection 资源很宝贵的,不建议将 Connection 当参数来传递
------解决方案--------------------string str = "user id=sa;password=000;initial catalog=glxtSQL;Server=KEYJOB;Connect Timeout=60; ";
SqlConnection conn = new SqlConnection(str);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from side where SideID=1 ";
cmd.Connection = con;
SqlDataReader dr=null;
try
{
dr = cmd.ExecuteReader();
if (dr.Read())
{
Response.Write(dr[ "SideLeft "].ToString());
}
}
catch (Exception ex)
{
// return ex;
}