#region 存储过程操作
/// <summary>
/// 执行存储过程,返回SqlDataReader ( 注意:调用该方法后,一定要对SqlDataReader进行Close )
/// </summary>
/// <param name="storedProcName">存储过程名</param>
/// <param name="parameters">存储过程参数</param>
/// <returns>SqlDataReader</returns>
public static DataSet RunProcedure(string storedProcName, IDataParameter[] parameters)
{
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
MySqlCommand cmd = new MySqlCommand(storedProcName, connection);
cmd.CommandType = CommandType.StoredProcedure;
if (parameters != null)
{
foreach (MySqlParameter parameter in parameters)
{
if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) &&
(parameter.Value == null))
{
parameter.Value = DBNull.Value;
}
cmd.Parameters.Add(parameter);
}
}
using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
try
{
da.Fill(ds, "ds");
cmd.Parameters.Clear();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
throw new Exception(ex.Message);
}
return ds;
}
}
}
#endregion
调用方法
DataSet ds = bll.GetProList("admin","admin");
<pre name="code" class="csharp">#region 自定义
/// <summary>
/// 分页获取数据列表
/// </summary>
public DataSet GetProList(string JobNo, string JobPwd)
{
MySqlParameter[] parameters = {
new MySqlParameter("@JobNo", MySqlDbType.VarChar, 10),
new MySqlParameter("@JobPwd", MySqlDbType.VarChar, 100),
};
parameters[0].Value = JobNo;
parameters[0].Direction = ParameterDirection.Input;
parameters[1].Value = JobPwd;
parameters[1].Direction = ParameterDirection.Input;
return DbHelperMySQL.RunProcedure("pro_GetGroupByJobNo", parameters);
}
#endregion