/// <summary> /// 调用存储过程(无结果集) /// </summary> /// <param name="mp"></param> /// <returns></returns> public static Exception CallProc(MakeParameter mp) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = mp.ProcName; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = DBM.Conn; for (int i = 0; i < mp.List.Count; i++) { cmd.Parameters.Add(mp.List[i]); } foreach (object key in mp.Table.Keys) { cmd.Parameters.Add(mp.Table[key]); } cmd.Connection.Open(); SqlTransaction tran = cmd.Connection.BeginTransaction(); cmd.Transaction = tran; try { cmd.ExecuteNonQuery(); tran.Commit(); } catch (Exception ex) { tran.Rollback(); return(ex); } finally { cmd.Connection.Close(); } return(null); }
/// <summary> /// 调用存储过程(有结果集) /// </summary> /// <param name="mp"></param> /// <returns></returns> public static DataSet CallProcWithDataSet(MakeParameter mp) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = mp.ProcName; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = DBM.Conn; for (int i = 0; i < mp.List.Count; i++) { cmd.Parameters.Add(mp.List[i]); } foreach (object key in mp.Table.Keys) { cmd.Parameters.Add(mp.Table[key]); } SqlDataAdapter dap = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); try { dap.Fill(ds); } catch { } finally { if (cmd.Connection.State != ConnectionState.Closed) { cmd.Connection.Close(); } } return(ds); }