BeginExecuteNonQuery 要求已打开且可用的连接.连接的当前状态为已关闭
classDataBase:IDisposable{privateSqlConnectioncon;privatevoidOpen(){if(con==null){str...
class DataBase:IDisposable
{
private SqlConnection con;
private void Open()
{
if (con == null)
{
string Strcon = "Data Source = STAR; Integrated Security = True; Initial Catalog=db_CMS";
con = new SqlConnection(Strcon);
if (con.State == System.Data.ConnectionState.Closed)
con.Open();
}
}
public void Close()
{
if (con != null)
con.Close();
}
public void Dispose()
{
if (con != null)
{
con.Dispose();
con = null;
}
}
public SqlParameter MakeInParam(string ParamName, SqlDbType DbType, int Size, object Value)
{
return MakeParam(ParamName, DbType, Size, ParameterDirection.Input, Value);
}
public SqlParameter MakeParam(string ParamName, SqlDbType DbType, Int32 Size, ParameterDirection Direction, object Value)
{
SqlParameter param;
if (Size > 0)
param = new SqlParameter(ParamName, DbType, Size);
else
param = new SqlParameter(ParamName, DbType);
param.Direction = Direction;
if (!(Direction == ParameterDirection.Output && Value == null))
param.Value = Value;
return param;
}
public int RunProc(string procName, SqlParameter[] prams)
{
SqlCommand cmd = CreateCommand(procName, prams);
cmd.BeginExecuteNonQuery();
this.Close();
return (int)cmd.Parameters["ReturnValue"].Value;
} 展开
{
private SqlConnection con;
private void Open()
{
if (con == null)
{
string Strcon = "Data Source = STAR; Integrated Security = True; Initial Catalog=db_CMS";
con = new SqlConnection(Strcon);
if (con.State == System.Data.ConnectionState.Closed)
con.Open();
}
}
public void Close()
{
if (con != null)
con.Close();
}
public void Dispose()
{
if (con != null)
{
con.Dispose();
con = null;
}
}
public SqlParameter MakeInParam(string ParamName, SqlDbType DbType, int Size, object Value)
{
return MakeParam(ParamName, DbType, Size, ParameterDirection.Input, Value);
}
public SqlParameter MakeParam(string ParamName, SqlDbType DbType, Int32 Size, ParameterDirection Direction, object Value)
{
SqlParameter param;
if (Size > 0)
param = new SqlParameter(ParamName, DbType, Size);
else
param = new SqlParameter(ParamName, DbType);
param.Direction = Direction;
if (!(Direction == ParameterDirection.Output && Value == null))
param.Value = Value;
return param;
}
public int RunProc(string procName, SqlParameter[] prams)
{
SqlCommand cmd = CreateCommand(procName, prams);
cmd.BeginExecuteNonQuery();
this.Close();
return (int)cmd.Parameters["ReturnValue"].Value;
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询