Пример #1
0
 /// <summary>
 /// 执行存储过程,并返回第一行第一单元的值
 /// </summary>
 public static object ScalarSP(string SPName)
 {
     SPParam temp = new SPParam(SPName);
     return ScalarSP(temp);
 }
Пример #2
0
 /// <summary>
 /// 执行存储过程,并返回受影响的行数
 /// </summary>
 public static int NonQuerySP(string SPName)
 {
     SPParam temp = new SPParam(SPName);
     return NonQuerySP(temp);
 }
Пример #3
0
 /// <summary>
 /// 执行存储过程,并返回第一行第一单元的值
 /// </summary>
 public static object ScalarSP(SPParam spp)
 {
     using (OleDbConnection myConn = GetNewConn())
     {
         OleDbCommand _OleDbCommand = GetSqlCmd(spp);
         _OleDbCommand.Connection = myConn;
         return _OleDbCommand.ExecuteScalar();
     }
 }
Пример #4
0
 /// <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);
     }
 }
Пример #5
0
            /// <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;
                }
            }
Пример #6
0
 /// <summary>
 /// 执行存储过程,返回DataSet
 /// </summary>
 /// <param name="spp"></param>
 /// <returns></returns>
 public static DataSet QuerySPtoDataSet(string SPName)
 {
     SPParam temp = new SPParam(SPName);
     return QuerySPtoDataSet(temp);
 }
Пример #7
0
            /// <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;
                }
            }
Пример #8
0
 /// <summary>
 /// 执行存储过程,并返回表
 /// </summary>
 public static DataTable QuerySP(string SPName)
 {
     SPParam temp = new SPParam(SPName);
     return QuerySP(temp);
 }
Пример #9
0
            /// <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;
                }
            }
Пример #10
0
            /// <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;

            }