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;
} 展开
启帆信息
2024-11-19 广告
2024-11-19 广告
启帆信息是英伟达中国区代理商,原厂授权代理,提供全面的软件技术解决方案以及NVIDIA以太网产品、交换机等产品,欢迎前来咨询!...
点击进入详情页
本回答由启帆信息提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询