Exemplo n.º 1
0
 /// <summary>
 /// 执行数据库语句支持存储过程,含输出参数 2013-07-01
 /// </summary>
 /// <param name="sql">存储过程名称</param>
 /// <param name="parList">参数</param>
 /// <param name="outParIdName">out 参数1名称</param>
 /// <param name="outParIdValue">out 参数1值(必须是int/long)</param>
 /// <param name="outParName">out 参数2名称</param>
 /// <param name="outParValue">out 参数2值 </param>
 /// <param name="dbT">数据库</param>
 /// <param name="cmdType">sql类型</param>
 /// <returns></returns>
 public static bool ExecuteNonQueryWithOutResult(string sql, List <ParameterEntity> parList, string outParIdName, out string outParIdValue, string outParName, out string outParValue, DataBaseType dbT, CommandType cmdType)
 {
     try
     {
         DbCommand      cmd;
         OracleDatabase oraDb = DBManager.CreateDataBase(dbT);
         if (cmdType == CommandType.StoredProcedure)
         {
             cmd = oraDb.GetStoredProcCommand(sql);
         }
         else
         {
             cmd = oraDb.GetSqlStringCommand(sql);
         }
         cmd.CommandType = cmdType;
         if (parList != null && parList.Count > 0)
         {
             foreach (ParameterEntity par in parList)
             {
                 oraDb.AddInParameter(cmd, par.Name, par.DbType, par.Value);
             }
         }
         if (!string.IsNullOrEmpty(outParIdName))
         {
             oraDb.AddOutParameter(cmd, outParIdName, DbType.Int64, 1024);
         }
         if (!string.IsNullOrEmpty(outParName))
         {
             oraDb.AddOutParameter(cmd, outParName, DbType.String, 1024);
         }
         oraDb.ExecuteNonQuery(cmd);
         if (!string.IsNullOrEmpty(outParIdName))
         {
             outParIdValue = cmd.Parameters[outParIdName].Value.ToString();
         }
         else
         {
             outParIdValue = "";
         }
         if (!string.IsNullOrEmpty(outParName))
         {
             outParValue = cmd.Parameters[outParName].Value.ToString();
         }
         else
         {
             outParValue = "";
         }
         return(true);
     }
     catch (Exception e)
     {
         outParValue = e.Message;
         throw e;
     }
 }