请好心的高手看看存储过程的问题
public class conndb{
protected SqlConnection Connection;
private string connectionString;
public conndb()
{
//
// TODO: 在此处添加构造函数逻辑
//
connectionString = System.Configuration.ConfigurationSettings.AppSettings["constring"];
Connection = new SqlConnection(connectionString);
}
public SqlCommand BuildIntCommand(string storedProcName, IDataParameter[] parameters)
{
SqlCommand command = BuildQueryCommand(storedProcName, parameters);
command.Parameters.Add(new SqlParameter("ReturnValue", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, 0, 0, string.Empty, DataRowVersion.Default, null));
return command;
}
public SqlCommand BuildQueryCommand(string storedProcName, IDataParameter[] parameters)
{
SqlCommand command = new SqlCommand(storedProcName, Connection);
command.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter parameter in parameters)
{
command.Parameters.Add(parameter);
}
return command;
}
protected string ConnectionString
{
get
{
return connectionString;
}
}
public int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected)
{
int result;
Connection.Open();
SqlCommand command = BuildIntCommand(storedProcName, parameters);
rowsAffected = command.ExecuteNonQuery();
result = (int)command.Parameters["ReturnValue"].Value;
Connection.Close();
Connection.Dispose();
return result;
}
}
请高手把BuildIntCommand,BuildQueryCommand,RunProcedure 写在一个方法里面并写上注释 谢谢了 --------------------编程问答-------------------- 这个。。。。 --------------------编程问答-------------------- 可能手误.
public int myUpdatedRunProcedure(string procName,IDataParameter[] parameters,string appConnKey,out int rowsAffected)
{
connStr = System.Configuration.ConfigurationSettings.AppSettings[appConnKey];
SqlConnection cn = new SqlConnection(connStr);
cn.Open();
SqlCommand cmd = new SqlCommand(procName,cn);
cmd.CommandType = CommandType.StoredProcedure;
foreach(SqlParameter pm in parameters)
{
cmd.Parameters.Add(pm);
}
rowsAffected = command.ExecuteNonQuery();
int result = (int)command.Parameters["ReturnValue"].Value;
cn.Close();
cn.Disponse();
return result;
}
补充:.NET技术 , ASP.NET