connection属性尚未初始化
privatestaticSqlConnectionconn;publicstaticSqlConnectionConn{get{stringconnString=Con...
private static SqlConnection conn;
public static SqlConnection Conn
{
get
{
string connString = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
//string connString = "server=.;database=SportShop;uid=hao;pwd=123456";
if (conn == null)
{
conn = new SqlConnection(connString);
conn.Open();
}
else if (conn.State == System.Data.ConnectionState.Closed)
{
conn.Open();
}
else if (conn.State == System.Data.ConnectionState.Broken)
{
conn.Close();
conn.Open();
}
return conn;
}
}
//执行一条带参数的Sql查询语句,查询结果以SqlDataReader的形式返回
public static SqlDataReader GetReader(string sql, params SqlParameter[] values)
{
SqlCommand cmd = new SqlCommand(sql,conn);
//cmd.Connection = conn;
cmd.Parameters.AddRange(values);
SqlDataReader reader = cmd.ExecuteReader( );
return reader;
}
}
connection属性尚未初始化 展开
public static SqlConnection Conn
{
get
{
string connString = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
//string connString = "server=.;database=SportShop;uid=hao;pwd=123456";
if (conn == null)
{
conn = new SqlConnection(connString);
conn.Open();
}
else if (conn.State == System.Data.ConnectionState.Closed)
{
conn.Open();
}
else if (conn.State == System.Data.ConnectionState.Broken)
{
conn.Close();
conn.Open();
}
return conn;
}
}
//执行一条带参数的Sql查询语句,查询结果以SqlDataReader的形式返回
public static SqlDataReader GetReader(string sql, params SqlParameter[] values)
{
SqlCommand cmd = new SqlCommand(sql,conn);
//cmd.Connection = conn;
cmd.Parameters.AddRange(values);
SqlDataReader reader = cmd.ExecuteReader( );
return reader;
}
}
connection属性尚未初始化 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询