要求已打开且可用的连接。连接的当前状态为打开 30
privatestaticSqlConnectionConn=newSqlConnection();privatestaticSqlCommandCmd=newSqlCo...
private static SqlConnection Conn = new SqlConnection();
private static SqlCommand Cmd = new SqlCommand();
/// <summary>
/// 打开连接
/// </summary>
public static void Open()
{
if (Conn.State.Equals(ConnectionState.Closed))
{
Conn.ConnectionString = (ConfigurationManager.ConnectionStrings["herpeisConnectionString"].ConnectionString);
Cmd.Connection = Conn;
Conn.Open();
}
}
/// <summary>
/// 关闭连接
/// </summary>
public static void Close()
{
if (Conn.State == ConnectionState.Open)
{
Conn.Close();
//Conn.Dispose();
//Cmd.Dispose();
}
}
public static DataSet GetDataSet(string sql)
{
try
{
Open();
SqlDataAdapter Da = new SqlDataAdapter(sql, Conn);
DataSet Ds = new DataSet();
Da.Fill(Ds);
return Ds;
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
finally
{
Close();
}
}
public static DataTable GetDataTable(string sql)
{
try
{
Open();
SqlDataAdapter Da = new SqlDataAdapter(sql, Conn);
DataTable Dt = new DataTable();
Da.Fill(Dt);
return Dt;
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
finally
{
Close();
}
}
public static int CountCmd(string sql)
{
try
{
Open();
Cmd.CommandType = CommandType.Text;
Cmd.CommandText = sql;
return (int)Cmd.ExecuteScalar();
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
finally
{
Close();
}
}
就是关闭的时候报错了...
有没有知道的啊...
汗,没有人回啊... 展开
private static SqlCommand Cmd = new SqlCommand();
/// <summary>
/// 打开连接
/// </summary>
public static void Open()
{
if (Conn.State.Equals(ConnectionState.Closed))
{
Conn.ConnectionString = (ConfigurationManager.ConnectionStrings["herpeisConnectionString"].ConnectionString);
Cmd.Connection = Conn;
Conn.Open();
}
}
/// <summary>
/// 关闭连接
/// </summary>
public static void Close()
{
if (Conn.State == ConnectionState.Open)
{
Conn.Close();
//Conn.Dispose();
//Cmd.Dispose();
}
}
public static DataSet GetDataSet(string sql)
{
try
{
Open();
SqlDataAdapter Da = new SqlDataAdapter(sql, Conn);
DataSet Ds = new DataSet();
Da.Fill(Ds);
return Ds;
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
finally
{
Close();
}
}
public static DataTable GetDataTable(string sql)
{
try
{
Open();
SqlDataAdapter Da = new SqlDataAdapter(sql, Conn);
DataTable Dt = new DataTable();
Da.Fill(Dt);
return Dt;
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
finally
{
Close();
}
}
public static int CountCmd(string sql)
{
try
{
Open();
Cmd.CommandType = CommandType.Text;
Cmd.CommandText = sql;
return (int)Cmd.ExecuteScalar();
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
finally
{
Close();
}
}
就是关闭的时候报错了...
有没有知道的啊...
汗,没有人回啊... 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询