Exemplo n.º 1
0
 /// <summary>
 /// Creates Connection Object with given ConnectionType And ConnectionString.
 /// </summary>
 /// <param name="ConnectionType">Connection Type</param>
 /// <param name="connectionString">Connection String</param>
 public Connection(ConnectionTypes ConnectionType, String connectionString)
 {
     dbConn = ConnectionObject.GetConnection(ConnectionType);
     dbConn.ConnectionString = connectionString;
     _ConnString             = connectionString;
     _ConnType = ConnectionType;
     AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(Resolver);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Get DataSet with given CommandType, Procedure Name Or Query And Hashtable.
        /// </summary>
        /// <param name="cmdType">CommandType cmdType Like Text, StoredProcedure, etc. </param>
        /// <param name="QueryOrProcedure">Procedure Name Or Query</param>
        /// <param name="parameters">Hashtable object contains parameters names and values.</param>
        /// <returns>>Returns System.Data.DataSet object</returns>
        public DataSet GetResultSet(CommandType cmdType, string QueryOrProcedure, Hashtable parameters)
        {
            try
            {
                dbConn.Open();
                dbTrans = dbConn.BeginTransaction();

                DataSet dataSet = new DataSet();

                using (IDbCommand dbCmd = dbConn.CreateCommand())
                {
                    dbCmd.Transaction = dbTrans;
                    dbCmd.CommandType = cmdType;
                    dbCmd.CommandText = QueryOrProcedure;
                    if (null != parameters)
                    {
                        IEnumerator keys = parameters.Keys.GetEnumerator();
                        while (keys.MoveNext())
                        {
                            IDataParameter dbParam = dbCmd.CreateParameter();

                            string key = keys.Current.ToString();
                            if (String.IsNullOrWhiteSpace(key))
                            {
                                throw new Exception("Parameter name could not be empty or null.");
                            }

                            dbParam.ParameterName = keys.Current.ToString();
                            dbParam.Value         = parameters[keys.Current];
                            dbCmd.Parameters.Add(dbParam);
                        }
                    }


                    IDataAdapter dbAdapter =
                        ConnectionObject.GetDataAdapter(_ConnType, dbCmd);

                    dbAdapter.Fill(dataSet);

                    dbCmd.Parameters.Clear();
                    dbTrans.Commit();
                }
                dbTrans.Dispose();
                dbConn.Close();

                return(dataSet);
            }
            catch (Exception exc)
            {
                if (null != dbTrans)
                {
                    dbTrans.Rollback();
                    dbTrans.Dispose();
                }
                if (null != dbConn)
                {
                    dbConn.Close();
                }
                throw exc;
            }
        }