midrange.com code scratchpad
Name:
DB Access Code
Scriptlanguage:
C#
Tabwidth:
4
Date:
09/24/2009 03:58:37 pm
IP:
Logged
Description:
The user was to lazy to give a description
Code:
  1.         public static DataSet ExecuteDataset(string commandText, CommandType commandType, params object[] parameters)
  2.         {
  3.             DataSet ds = new DataSet();
  4.             
  5.             using (iDB2Connection cn = GetConnection())
  6.             {
  7.                 iDB2Command cm = cn.CreateCommand();
  8.                 cm.CommandText = commandText;
  9.                 cm.CommandType = commandType;
  10.  
  11.                 cn.Open();
  12.                 if (log.IsDebugEnabled)
  13.                 {
  14.                     log.DebugFormat("Job: {0}", cn.JobName);
  15.                     log.DebugFormat("Library list: {0}", cn.LibraryList);
  16.                     log.DebugFormat("Options library: {0}", cn.QueryOptionsFileLibrary);
  17.                 }
  18.  
  19.                 //Got parameters?
  20.                 if (null != parameters)
  21.                 {
  22.                     cm.DeriveParameters();
  23.                     for (int i = 0; i < parameters.Length; i++)
  24.                         cm.Parameters[i].Value = parameters[i];
  25.                 }
  26.  
  27.                 iDB2DataAdapter da = new iDB2DataAdapter(cm);
  28.                 da.Fill(ds);
  29.             }
  30.  
  31.             return ds;
  32.             
  33.         }
  34.  
  35.  
  36.         #region GetCS()
  37.         static protected string GetCS()
  38.         {
  39.                 return ConfigurationManager.AppSettings["ConnectionString"];
  40.         }
  41.         #endregion
  42.  
  43.         #region GetConnection()
  44.         private static iDB2Connection GetConnection()
  45.         {
  46.             iDB2Connection cn = new iDB2Connection();
  47.             cn.ConnectionString = GetCS();
  48.             return cn;
  49.         }
  50.         #endregion
© 2004-2019 by midrange.com generated in 0.007s valid xhtml & css