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:
- public static DataSet ExecuteDataset(string commandText, CommandType commandType, params object[] parameters)
- {
- DataSet ds = new DataSet();
-
- using (iDB2Connection cn = GetConnection())
- {
- iDB2Command cm = cn.CreateCommand();
- cm.CommandText = commandText;
- cm.CommandType = commandType;
-
- cn.Open();
- if (log.IsDebugEnabled)
- {
- log.DebugFormat("Job: {0}", cn.JobName);
- log.DebugFormat("Library list: {0}", cn.LibraryList);
- log.DebugFormat("Options library: {0}", cn.QueryOptionsFileLibrary);
- }
-
-
- if (null != parameters)
- {
- cm.DeriveParameters();
- for (int i = 0; i < parameters.Length; i++)
- cm.Parameters[i].Value = parameters[i];
- }
-
- iDB2DataAdapter da = new iDB2DataAdapter(cm);
- da.Fill(ds);
- }
-
- return ds;
-
- }
-
-
- #region GetCS()
- static protected string GetCS()
- {
- return ConfigurationManager.AppSettings["ConnectionString"];
- }
- #endregion
-
- #region GetConnection()
- private static iDB2Connection GetConnection()
- {
- iDB2Connection cn = new iDB2Connection();
- cn.ConnectionString = GetCS();
- return cn;
- }
- #endregion
|
|
|