示例#1
0
 public object[] ExecCollect(string strProcedureName, ClsProcedureParameter objPar)
 {
     SqlCommand command = conn.CreateCommand();
     SqlDataReader reader = null;
     object[] objrtn = null;
     try
     {
         command.CommandType = CommandType.StoredProcedure;
         command.CommandText = strProcedureName;
         if (objPar != null)
         {
             objPar.FillParameter(command);
         }
         reader = command.ExecuteReader();
         if (reader == null)
         {
             objrtn = null;
         }
         if (reader.Read())
         {
             if (reader.FieldCount < 1)
             {
                 objrtn = null;
             }
             else
             {
                 objrtn = new object[reader.FieldCount];
                 for (int i = 0; i < reader.FieldCount; ++i)
                 {
                     objrtn[i] = reader.GetValue(i);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Common.Log.LogError(ex.ToString(), strProcedureName + ",Access执行带参数非查询返回对象");
     }
     finally
     {
         reader.Close();
         command.Dispose();
     }
     return objrtn;
 }
示例#2
0
 /// <summary>
 /// 执行有参存储过程返回结果集
 /// </summary>
 /// <param name="strProcedureName">存储过程名字</param>
 /// <param name="objPar">存储过程参数对象</param>
 /// <returns>DATATable</returns>
 public DataTable ExecQuery(string strProcedureName, ClsProcedureParameter objPar)
 {
     SqlCommand command = conn.CreateCommand();
     SqlDataAdapter adapter = new SqlDataAdapter();
     DataTable tmpTable = null;
     try
     {
         command.CommandType = CommandType.StoredProcedure;
         command.CommandText = strProcedureName;
         if (objPar != null)
         {
             objPar.FillParameter(command);	//填充command
         }
         tmpTable = new DataTable();
         adapter.SelectCommand = command;
         adapter.Fill(tmpTable);
     }
     catch (Exception ex)
     {
         Common.Log.LogError(ex.ToString(), strProcedureName + ",Access执行带参数查询");
     }
     finally
     {
         command.Dispose();
         adapter.Dispose();
     }
     return tmpTable;
 }
示例#3
0
        public DataTable ExecuteQueryByPage(ClsProcedureParameter objPara)
        {
            SqlCommand command = conn.CreateCommand();
            SqlDataAdapter adapter = new SqlDataAdapter();
            DataTable tmpTable = null;
            try
            {
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "commonPage";
                if (objPara != null)
                {
                    objPara.FillParameter(command);
                }
                tmpTable = new DataTable();
                adapter.SelectCommand = command;
                adapter.Fill(tmpTable);

            }
            catch (Exception ex)
            {
                Common.Log.LogError(ex.ToString(), "commonMyPage" + ",ExecuteQueryByPage");
            }
            finally
            {
                command.Dispose();
            }
            return tmpTable;
        }
示例#4
0
 /// <summary>
 /// 执行insert等操作的存储过程
 /// </summary>
 /// <param name="strProcedureName">存储过程名字</param>
 /// <param name="objPar">存储过程参数对象</param>
 /// <returns>bool</returns>
 public bool ExecNoQuery(string strProcedureName, ClsProcedureParameter objPar)
 {
     SqlCommand command = conn.CreateCommand();
     bool Result = false;
     try
     {
         command.CommandType = CommandType.StoredProcedure;
         command.CommandText = strProcedureName;
         if (objPar != null)
         {
             objPar.FillParameter(command);
         }
         command.ExecuteNonQuery();
         Result = true;
     }
     catch (Exception ex)
     {
         Common.Log.LogError(ex.ToString(), strProcedureName + ",Access执行带参数非查询");
     }
     finally
     {
         command.Dispose();
     }
     return Result;
 }