/// <summary> /// 执行存储过程,并返回第一行第一单元的值 /// </summary> public static object ScalarSP(string SPName) { SPParam temp = new SPParam(SPName); return ScalarSP(temp); }
/// <summary> /// 执行存储过程,并返回受影响的行数 /// </summary> public static int NonQuerySP(string SPName) { SPParam temp = new SPParam(SPName); return NonQuerySP(temp); }
/// <summary> /// 执行存储过程,并返回第一行第一单元的值 /// </summary> public static object ScalarSP(SPParam spp) { using (OleDbConnection myConn = GetNewConn()) { OleDbCommand _OleDbCommand = GetSqlCmd(spp); _OleDbCommand.Connection = myConn; return _OleDbCommand.ExecuteScalar(); } }
/// <summary> /// 执行存储过程,并返回受影响的行数 /// </summary> public static int NonQuerySP(SPParam spp) { try { using (OleDbConnection myConn = GetNewConn()) { OleDbCommand _OleDbCommand = GetSqlCmd(spp); _OleDbCommand.Connection = myConn; return _OleDbCommand.ExecuteNonQuery(); } } catch (Exception ex) { throw new Exception("sd", ex); } }
/// <summary> /// 执行存储过程,返回受影响的行数(有返回参数) /// </summary> public static int NonQuerySPR(SPParam spp) { using (OleDbConnection myConn = GetNewConn()) { OleDbCommand _OleDbCommand = GetSqlCmd(spp); _OleDbCommand.Connection = myConn; int result = _OleDbCommand.ExecuteNonQuery(); foreach (SqlParameter pobj in _OleDbCommand.Parameters) { spp[pobj.ParameterName] = pobj.Value; } return result; } }
/// <summary> /// 执行存储过程,返回DataSet /// </summary> /// <param name="spp"></param> /// <returns></returns> public static DataSet QuerySPtoDataSet(string SPName) { SPParam temp = new SPParam(SPName); return QuerySPtoDataSet(temp); }
/// <summary> /// 执行存储过程,返回DataSet /// </summary> /// <param name="spp"></param> /// <returns></returns> public static DataSet QuerySPtoDataSet(SPParam spp) { using (OleDbConnection myConn = GetNewConn()) { OleDbCommand _OleDbCommand = GetSqlCmd(spp); _OleDbCommand.Connection = myConn; OleDbDataAdapter _OleDbDataAdapter = new OleDbDataAdapter(_OleDbCommand); DataSet _ds = new DataSet("returnDataSet"); _OleDbDataAdapter.Fill(_ds); return _ds; } }
/// <summary> /// 执行存储过程,并返回表 /// </summary> public static DataTable QuerySP(string SPName) { SPParam temp = new SPParam(SPName); return QuerySP(temp); }
/// <summary> /// 执行存储过程,并返回表 /// </summary> public static DataTable QuerySP(SPParam spp) { using (OleDbConnection myConn = GetNewConn()) { OleDbCommand _OleDbCommand = GetSqlCmd(spp); _OleDbCommand.Connection = myConn; OleDbDataAdapter _OleDbDataAdapter = new OleDbDataAdapter(_OleDbCommand); DataTable _dt = new DataTable("returnTable"); _OleDbDataAdapter.Fill(_dt); return _dt; } }
/// <summary> /// 构造OleDbCommand /// </summary> /// <param name="spp"></param> /// <returns></returns> private static OleDbCommand GetSqlCmd(SPParam spp) { OleDbCommand _OleDbCommand = new OleDbCommand(); _OleDbCommand.CommandType = CommandType.StoredProcedure; _OleDbCommand.CommandText = spp.m_SpName; foreach (string Pname in spp.m_Param.Keys) { SqlParameter myParam = new SqlParameter(Pname, ((ParamObj)spp.m_Param[Pname]).PValue); myParam.Direction = (ParameterDirection)(((ParamObj)spp.m_Param[Pname]).PDirection); _OleDbCommand.Parameters.Add(myParam); } return _OleDbCommand; }