/// <summary> /// 通过存储过程得到DataReader对象 /// </summary> /// <param name="spName">存储过程名称</param> /// <param name="parms">存储过程参数数组</param> /// <returns>SqlDataReader对象,失败为null</returns> public MySqlDataReader GetReader(string spName, MySqlParameter[] parms) { try { Open(); Com = new MySqlCommand(); Com.Connection = Conn; Com.CommandType = CommandType.StoredProcedure; Com.CommandText = spName; for (int intCounter = 0; intCounter < parms.GetLength(0); intCounter++) { Com.Parameters.Add(parms[intCounter]); } Dr = Com.ExecuteReader(CommandBehavior.CloseConnection); return Dr; } catch (MySqlException) { return null; } finally { Com.Parameters.Clear(); } }
/// <summary> /// 用于执行没有返回值的存储过程,包括Update,Insert,Delete /// </summary> /// <param name="pstrStoreProcedureName">存储过程名</param> /// <param name="pParams">存储过程的参数数组</param> /// <returns>执行结果:-1失败;其他:影响的行数</returns> public int ExecuteNonQuery(string pstrStoreProcedureName, MySqlParameter[] pParams) { int Result; try { if (Conn.State == ConnectionState.Closed) { Open(); } Com = new MySqlCommand(); Com.Connection = Conn; Com.CommandType = CommandType.StoredProcedure; Com.CommandText = pstrStoreProcedureName; for (int intCounter = 0; intCounter < pParams.GetLength(0); intCounter++) { Com.Parameters.Add(pParams[intCounter]); } Result = Com.ExecuteNonQuery(); } catch (MySqlException) { return -1; } finally { Com.Parameters.Clear(); Com.Dispose(); Close(); Conn.Dispose(); } return Result; }
/// <summary> /// 调研存储过程得到DataSet /// </summary> /// <param name="spName">存储过程名</param> /// <param name="parms">存储过程参数数组</param> /// <returns>Dataset对象,失败为null</returns> public DataSet GetDataSet(string spName, MySqlParameter[] parms) { try { Open(); Adp = new MySqlDataAdapter(spName, Conn); Adp.SelectCommand.CommandType = CommandType.StoredProcedure; for (int intCounter = 0; intCounter < parms.GetLength(0); intCounter++) { Adp.SelectCommand.Parameters.Add(parms[intCounter]); } Ds = new DataSet(); Adp.Fill(Ds, "ds"); return Ds; } catch (MySqlException) { return null; } finally { Adp.SelectCommand.Parameters.Clear(); Adp.Dispose(); Close(); } }