/// <summary>
        /// Executes a command returning a DataSet.
        /// </summary>
        /// <param name="strTablename">Table name.</param>
        /// <returns>Result DataSte object.</returns>
        public DataSet ExecuteDataSet(String strTablename)
        {
            ExecuteDataAdapter();

            m_Dataset = new DataSet();

            try
            {
                // Fill DataSet
                m_Dataset = new System.Data.DataSet(strTablename);
                m_SqlDataAdapter.Fill(m_Dataset);
                m_SqlConnection.Close();
            }
            catch (Exception e)
            {
                this.blnError        = true;
                this.strErrorMessage = e.Message;

                if (DbBase.ThrowExceptionIsOn)
                {
                    throw e;
                }
            }

            return(m_Dataset);
        }
Esempio n. 2
0
        private static void Extract()
        {
            myDatabase.Command.CommandType = CommandType.Text;
            myDatabase.Command.CommandText = "select* from invoices where orderdate > @LastRunDate order by salesperson, customerid, orderdate, productid";
            var v = myDatabase.CreateParameter;

            v.ParameterName = "LastRunDate";
            v.Value         = new DateTime(1996, 1, 1);
            v.DbType        = DbType.DateTime;
            myDatabase.Command.Parameters.Add(v);

            IDataAdapter myAdapter = myDatabase.DbDataAdapter;

            _invoiceTable = new DataSet();
            myAdapter.Fill(_invoiceTable);

            //foreach (DataRow row in _invoiceTable.Tables[0].Rows)
            //{
            //    Console.WriteLine("{0}-{1}-{2}", row[0], row[1], row[2]);
            //}
            ShowOutput(_invoiceTable, 3);
            myDatabase.Connection.Close();

            myDatabase.Command.CommandType = CommandType.Text;
            myDatabase.Command.CommandText = "select FirstName + LastName, (select(count(*)) from Employees where ReportsTo = e.EmployeeId) from Employees e";
            myAdapter      = myDatabase.DbDataAdapter;
            _employeeTable = new DataSet();
            myAdapter.Fill(_employeeTable);
            foreach (DataRow row in _employeeTable.Tables[0].Rows)
            {
                Console.WriteLine("{0}-{1}", row[0], row[1]);
            }
        }
Esempio n. 3
0
        public static List <Event> GetSystemEvent(this TableOperations <Event> eventTable, DateTime startTime, DateTime endTime, double timeTolerance)
        {
            AdoDataConnection connection = eventTable.Connection;

            using (IDbCommand command = connection.Connection.CreateCommand())
            {
                command.CommandText    = "GetSystemEvent";
                command.CommandType    = CommandType.StoredProcedure;
                command.CommandTimeout = connection.DefaultTimeout;
                AddParameter(command, "startTime", startTime, DbType.DateTime2);
                AddParameter(command, "endTime", endTime, DbType.DateTime2);
                AddParameter(command, "timeTolerance", timeTolerance, DbType.Double);

                IDataAdapter adapter = (IDataAdapter)Activator.CreateInstance(connection.AdapterType, command);

                using (adapter as IDisposable)
                {
                    DataSet dataSet = new DataSet();

                    adapter.Fill(dataSet);

                    return(dataSet.Tables[0].Rows
                           .Cast <DataRow>()
                           .Select(row => eventTable.LoadRecord(row))
                           .ToList());
                }
            }
        }
Esempio n. 4
0
        public override T GetFromDirectQuery(string sqlQuery, params IDbDataParameter[] sqlParameters)
        {
            try {
                IDataAdapter dbAdapter = GetAdapter(m_storageType, m_dbConnStr, sqlQuery, sqlParameters);

                if (dbAdapter != null)
                {
                    DataSet assetSet = new DataSet();
                    dbAdapter.Fill(assetSet);
                    if (assetSet != null && assetSet.Tables[0].Rows.Count == 1)
                    {
                        T asset = new T();
                        asset.Load(assetSet.Tables[0].Rows[0]);
                        return(asset);
                    }
                    else if (assetSet != null && assetSet.Tables[0].Rows.Count > 1)
                    {
                        throw new ApplicationException("Query submitted to GetFromDirectQuery returned more than one row. SQL=" + sqlQuery + ".");
                    }
                }

                return(default(T));
            }
            catch (Exception excp) {
                logger.Error("Exception DBLinqAssetPersistor GetDirect (" + typeof(T).Name + "). " + excp.Message);
                return(default(T));
            }
        }
 private void OkuyucuListe_Load(object sender, EventArgs e)
 {
     da = new SqlDataAdapter("SELECT * FROM Okuyucu_Bilgileri", baglanti);
     ds = new DataSet();
     da.Fill(ds);
     dataGridView1.DataSource = ds.Tables[0];
 }
Esempio n. 6
0
        private void btnTestExec_Click(object sender, EventArgs e)
        {
            IDbConnection con = GetDBConnection();

            con.Open();
            IDbCommand cmd = GetDBCommand(con);

            cmd.CommandText = txtTestSQL.Text;
            cmd.CommandText = new Regex("^\\s*[gG][Oo]\\s*$", RegexOptions.Multiline).Replace(cmd.CommandText, "");
            txtMsg.Text     = "";
            GetCommonParas(ref cmd);
            if (cbTestDebug.Checked)
            {
                if (con is SqlConnection)
                {
                    cmd.CommandText = "BEGIN TRAN;\r\n" + cmd.CommandText + "\r\nROLLBACK TRAN;\r\n";
                }
                else if (con is MySqlConnection)
                {
                    cmd.CommandText = "SET AUTOCOMMIT=0;\r\nBEGIN;\r\n" + cmd.CommandText + "\r\nROLLBACK;\r\nROLLBACK;\r\nSET AUTOCOMMIT=1;\r\n";
                }
            }
            try
            {
                IDataAdapter da = cmd is SqlCommand
                    ? (IDataAdapter) new SqlDataAdapter(cmd as SqlCommand)
                    : (IDataAdapter) new MySqlDataAdapter(cmd as MySqlCommand);
                ds = new DataSet();
                da.Fill(ds);
                if (ds.Tables.Count > 0)
                {
                    gridTest.DataSource = ds.Tables[0];
                }
                else
                {
                    gridTest.DataSource = new DataTable();
                }
                gridTest.Update();
                tables = new List <DataTable>();
                foreach (DataTable dt in ds.Tables)
                {
                    tables.Add(dt);
                }
                lbGrid.DataSource = tables;
                lbGrid.Update();
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    txtMsg.Text = ex.InnerException.Message;
                }
                else
                {
                    txtMsg.Text = ex.Message;
                }
            }

            con.Close();
        }
    public int ExecuteDataAdapterDataTableWithParams <T>(IDbCommand podbCommand, ref T pdtDT) where T : DataTable
    {
        IDataAdapter   ldaDataAdapter = default(IDataAdapter);
        IDbTransaction lodbTrans      = default(IDbTransaction);
        int            liFetchedRows  = 0;

        lodbTrans = EstablishConnection();
        try
        {
            podbCommand.Connection  = coConnection;
            podbCommand.Transaction = lodbTrans;
            ldaDataAdapter          = GetDataAdapter(ref podbCommand);
            ldaDataAdapter.TableMappings.Add("Table", pdtDT.TableName);
            liFetchedRows = ldaDataAdapter.Fill(pdtDT.DataSet);
            liFetchedRows = pdtDT.Rows.Count;
        }
        catch (Exception ex)
        {
            throw (ex);
        }
        finally
        {
            CloseConnection(ref lodbTrans);
        }
        return(liFetchedRows);
    }
Esempio n. 8
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Permet de vérouiller l'appel d'un seul DataAdapter à la fois par connexion
 /// </summary>
 /// <param name="adapter"></param>
 /// <param name="ds"></param>
 public void FillAdapter(IDataAdapter adapter, DataSet ds)
 {
     lock (m_lockerAdapter)
     {
         adapter.Fill(ds);
     }
 }
Esempio n. 9
0
        public override List <T> GetListFromDirectQuery(string sqlQuery, params IDbDataParameter[] sqlParameters)
        {
            try {
                IDataAdapter dbAdapter = GetAdapter(m_storageType, m_dbConnStr, sqlQuery, sqlParameters);

                if (dbAdapter != null)
                {
                    DataSet assetSet = new DataSet();
                    dbAdapter.Fill(assetSet);
                    if (assetSet != null)
                    {
                        List <T> assets = new List <T>();

                        foreach (DataRow row in assetSet.Tables[0].Rows)
                        {
                            T asset = new T();
                            asset.Load(row);
                            assets.Add(asset);
                        }

                        return(assets);
                    }
                }

                return(null);
            }
            catch (Exception excp) {
                logger.Error("Exception DBLinqAssetPersistor GetListFromDirectQuery (" + typeof(T).Name + "). " + excp.Message);
                return(null);
            }
        }
        public static object ExecSqlCommand(IDbConnection Connection, IDbCommand Command, bool ReturnDataSet, IDataAdapter DataAdapter)
        {
            Connection.Open();
            int    rows;
            object returnValue = null;

            Command.Connection = Connection;
            if (ReturnDataSet)
            {
                var ds = new DataSet();
                DataAdapter.Fill(ds);
                returnValue = ds;
                returnValue = ds.Tables[0];

                //if (ds.Tables.Count >= 1)
                //{
                //    if (ds.Tables[0].Rows.Count >= 1)
                //    {
                //        //returnValue = DataSetToJsonString(ds);
                //        returnValue = ds.Tables[0].Rows[0].ItemArray;
                //    }
                //}
            }
            else
            {
                rows        = Command.ExecuteNonQuery();
                returnValue = rows;
            }

            Connection.Close();
            return(returnValue);
        }
        /// <summary>
        /// Executes SQL commands that return rows and fill a DataSet
        /// with the results.
        /// </summary>
        /// <param name="CmdText">Command text</param>
        /// <returns>DataSet containing results</returns>
        public DataSet FillDataSet(string CmdText)
        {
            DataSet       dataSet    = null;    // DataSet to return
            IDataAdapter  adapter    = null;    // Data adapter
            IDbCommand    command    = null;    // Database command
            IDbConnection connection = null;    // Database connection

            try
            {
                connection = this.GetConnection();
                command    = this.GetCommand(CmdText, connection);
                adapter    = this.GetDataAdapter(command);

                // The data adapter will open and close the connection
                dataSet = new DataSet();
                adapter.Fill(dataSet);
                return(dataSet);
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.Message);
                return(null);
            }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
Esempio n. 12
0
        public virtual DataSet GetDataSetAll(string sql, params SugarParameter[] parameters)
        {
            if (this.ProcessingEventStartingSQL != null)
            {
                ExecuteProcessingSQL(ref sql, parameters);
            }
            ExecuteBefore(sql, parameters);
            IDataAdapter dataAdapter = this.GetAdapter();
            IDbCommand   sqlCommand  = GetCommand(sql, parameters);

            this.SetCommandToAdapter(dataAdapter, sqlCommand);
            DataSet ds = new DataSet();

            dataAdapter.Fill(ds);
            if (this.IsClearParameters)
            {
                sqlCommand.Parameters.Clear();
            }
            ExecuteAfter(sql, parameters);
            if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null)
            {
                this.Close();
            }
            return(ds);
        }
Esempio n. 13
0
        /// <summary>
        /// 执行存储过程,返回DataSet
        /// </summary>
        /// <param name="strSql">sql</param>
        /// <param name="isPro">是否是存储过程--true:是,false:否</param>
        /// <param name="paramenters">参数集</param>
        /// <returns></returns>
        public DataSet getDataSet(string strSql, bool isPro, params IDataParameter[] paramenters)
        {
            //替换数据库连接字符串
            if (intDatabaseType == 1)
            {
                strSql = strSql.Replace("@", this.strCharacter);
            }

            DataSet ds = new DataSet();

            if (isConnect())
            {
                IDbCommand cmd = null;
                try
                {
                    cmd             = myDB.getCmd();
                    cmd.Connection  = conn;
                    cmd.CommandText = strSql;
                    cmd.CommandType = CommandType.Text;
                    if (paramenters != null)
                    {
                        foreach (IDbDataParameter parm in paramenters)
                        {
                            cmd.Parameters.Add(parm);
                        }
                    }
                    if (isPro)
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        //针对Oracle特殊处理下
                        if (intDatabaseType == 1)
                        {
                            OracleParameter op = new OracleParameter("my_cursor", OracleType.Cursor);
                            op.Direction = ParameterDirection.Output;
                            cmd.Parameters.Add(op);
                        }
                    }
                    else
                    {
                        cmd.CommandType = CommandType.Text;
                    }

                    IDataAdapter iada = myDB.getDataAdapte(cmd);

                    iada.Fill(ds);

                    cmd.Parameters.Clear();
                }
                catch (Exception exp)
                {
                    exErr = exp.ToString();
                }
                finally
                {
                    cmd.Dispose();
                    cmd = null;
                }
            }
            return(ds);
        }
Esempio n. 14
0
        /// <summary>
        /// Return the DataSet
        /// </summary>
        /// <param name="connectionString">Connection String</param>
        /// <param name="cmdText">Sql</param>
        /// <param name="cmdType">CommandType,default value is CommandType.Text</param>
        /// <param name="cmdParms">DbParameter</param>
        /// <returns>The DataSet</returns>
        public DataSet ExecuteDataSet(string connectionString, string cmdText, CommandType cmdType = CommandType.Text, params DbParameter[] cmdParms)
        {
            try
            {
                DbCommand cmd = GetCmd();

                using (DbConnection conn = GetConn(connectionString))
                {
                    PrepareCommand(conn, null, cmd, cmdType, cmdText, cmdParms);

                    IDataAdapter da = GetAdapter(cmd);

                    var ds = new DataSet();

                    da.Fill(ds);

                    conn.Close();

                    cmd.Parameters.Clear();

                    return(ds);
                }
            }
            catch (Exception)
            {
                LogHelper.LogError("When execute this sql =>" + cmdText);
                throw;
            }
        }
Esempio n. 15
0
 /// <summary>
 /// 执行查询语句,返回DataSet
 /// </summary>
 /// <param name="SQLString">查询语句</param>
 /// <returns>DataSet</returns>
 public DataSet Query(string sqlString)
 {
     using (IDbConnection iConn = this.GetConnection())
     {
         using (IDbCommand iCmd = GetCommand(sqlString, iConn))
         {
             DataSet ds = new DataSet();
             iConn.Open();
             try
             {
                 IDataAdapter iAdapter = this.GetAdapater(sqlString, iConn);
                 iAdapter.Fill(ds);
                 return(ds);
             }
             catch (System.Exception ex)
             {
                 throw new Exception(ex.Message);
             }
             finally
             {
                 if (iConn.State != ConnectionState.Closed)
                 {
                     iConn.Close();
                 }
             }
         }
     }
 }
Esempio n. 16
0
        protected DataSet AdapterFill(string strQuery, IDataParameter[] parameters, CommandType typeComm)
        {
            DataSet      dataSet     = new DataSet();
            IDataAdapter dataAdapter = this.con.DataAdapter(strQuery, parameters, typeComm);

            if (this.con.ExistError)
            {
                this.ExistError = this.con.ExistError;
                this.msgError   = this.con.MsgError;
            }
            else
            {
                try
                {
                    dataAdapter.Fill(dataSet);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    this.ExistError = true;
                    this.msgError   = exception.Message.Replace("\"", "'").Replace("\r", "").Replace("\n", "\\n");
                }
            }
            return(dataSet);
        }
Esempio n. 17
0
        /// <summary>
        /// 执行查询,并以指定的(具有数据架构的)数据集来填充数据
        /// </summary>
        /// <param name="SQL">查询语句</param>
        /// <param name="commandType">命令类型</param>
        /// <param name="parameters">查询参数</param>
        /// <param name="schemaDataSet">指定的(具有数据架构的)数据集</param>
        /// <returns>具有数据的数据集</returns>
        public virtual DataSet ExecuteDataSetWithSchema(string SQL, CommandType commandType, IDataParameter[] parameters, DataSet schemaDataSet)
        {
            if (!OnCommandExecuting(ref SQL, commandType, parameters))
            {
                return(null);
            }
            IDbConnection conn = GetConnection();
            IDbCommand    cmd  = conn.CreateCommand();

            CompleteCommand(cmd, SQL, commandType, parameters);
            IDataAdapter ada = GetDataAdapter(cmd);

            try
            {
                //使用MyDB.Intance 连接不能及时关闭?待测试
                ada.Fill(schemaDataSet);//FillSchema(ds,SchemaType.Mapped )
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                bool inTransaction = cmd.Transaction == null ? false : true;
                OnCommandExecuteError(cmd, ErrorMessage);
                if (OnErrorThrow)
                {
                    throw new QueryException(ErrorMessage, cmd.CommandText, commandType, parameters, inTransaction, conn.ConnectionString, ex);
                }
            }
            finally
            {
                OnCommandExected(cmd, -1);
                CloseConnection(conn, cmd);
            }
            return(schemaDataSet);
        }
Esempio n. 18
0
 //执行查询语句,返回DataTable,重点用于Oracle数据库
 public DataTable ExcuteQuery(string DbType, string SqlString)
 {
     using (IDbConnection iConn = GetConnection(DbType))
     {
         DataSet Ds = new DataSet();
         iConn.Open();
         try
         {
             IDataAdapter iAdapter = GetAdapter(DbType, SqlString, iConn);
             iAdapter.Fill(Ds);
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message);
         }
         finally
         {
             if (iConn.State != ConnectionState.Closed)
             {
                 iConn.Close();
             }
         }
         return(Ds.Tables[0]);
     }
 }
Esempio n. 19
0
        public DataSet ExecuteDataSet(string string_0)
        {
            IDbConnection dbConnection = null;
            IDbCommand    dbCommand    = null;
            DataSet       result;

            try
            {
                dbConnection = this.method_0();
                dbCommand    = this.method_1(string_0, dbConnection);
                IDataAdapter dataAdapter = this.method_3(dbCommand);
                DataSet      dataSet     = new DataSet();
                dataAdapter.Fill(dataSet);
                result = dataSet;
            }
            catch (Exception)
            {
                result = null;
            }
            finally
            {
                if (dbCommand != null)
                {
                    dbCommand.Dispose();
                }
                if (dbConnection != null)
                {
                    dbConnection.Dispose();
                }
            }
            return(result);
        }
Esempio n. 20
0
        private void CreateDataSet()
        {
            var conn      = new SqlConnection(BooksConnStr);
            var selectCmd = new SqlCommand(SELECT_CMD, conn);
            var updatecmd = new SqlCommand(UPDATE_BOOKS_CMD, conn);

            // Необходимы параметры, чтобы объект DataSet мог
            // подставлять корректные значения для столбцов
            updatecmd.Parameters.AddRange(new SqlParameter[]
            {
                new SqlParameter("@BookID", SqlDbType.Int, 4, "BookID"),
                new SqlParameter("@Title", SqlDbType.VarChar, 255, "Title"),
                new SqlParameter("@PublishYear", SqlDbType.Int, 4, "PublishYear")
            });

            var adapter = new SqlDataAdapter();

            adapter.TableMappings.Add("Table", "Books");
            adapter.SelectCommand = selectCmd;
            adapter.UpdateCommand = updatecmd;
            _conn    = conn;
            _adapter = adapter;
            _dataSet = new DataSet("Books");

            // Поместить все строки в набор данных
            _adapter.Fill(_dataSet);
        }
Esempio n. 21
0
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="TQueryForm"></typeparam>
        /// <param name="mapper"></param>
        /// <param name="session"></param>
        /// <param name="command"></param>
        /// <param name="statementName"></param>
        /// <param name="form"></param>
        /// <param name="enableLog"></param>
        /// <returns></returns>
        public static List<TEntity> QueryForPaging<TEntity, TQueryForm>(ISqlMapper mapper,
            ISqlMapSession session,
            IDbCommand command,
            string statementName,
            TQueryForm form,
            bool enableLog = true)
            where TEntity : IEntity
            where TQueryForm : IQueryForm
        {
            IPagingSQL paging = PagingSQLFactory.Create(mapper.DataSource.DbProvider.Name);
            var sql = mapper.GetRuntimeSql(statementName, form, session);

            if (form.StartIndex > -1 && form.EndIndex > -1)
            {
                sql = paging.GetPagingSQL(sql, form.OrderByColumn, form.StartIndex.Value, form.EndIndex.Value, form.OrderBy);
            }
            sql = paging.BuildOrderBy(sql, form.OrderByColumn, form.OrderBy);
            command.CommandText = sql;
            string paramString = BuildParams(mapper, statementName, form, command);

            IDataAdapter dataAdapter = session.CreateDataAdapter(command);

            DataSet set = new DataSet();
            dataAdapter.Fill(set);
            DataTable table = set.Tables[0];
            var list = table.ToList<TEntity>().ToList();
            if (enableLog)
            {
                SimpleLogger logger = new SimpleLogger();
                logger.Write(sql, true);
                logger.Write(paramString, true);
            }
            return list;
        }
Esempio n. 22
0
        public DataTable Query(string sSql)
        {
            DataTable dt = null;

            using (IDbConnection iConn = this.GetConnection())
            {
                using (IDbCommand iCmd = GetCommand(sSql, iConn))
                {
                    DataSet ds = new DataSet();
                    iConn.Open();
                    try
                    {
                        IDataAdapter iAdapter = this.GetAdapater(sSql, iConn);
                        iAdapter.Fill(ds);

                        if (ds != null && ds.Tables.Count > 0)
                        {
                            dt = ds.Tables[0];
                        }
                    }
                    catch (System.Exception ex)
                    {
                        //throw new Exception(ex.Message);
                    }
                    finally
                    {
                        if (iConn.State != ConnectionState.Closed)
                        {
                            iConn.Close();
                        }
                    }
                }
            }
            return(dt);
        }
Esempio n. 23
0
        public DataTable CreateTable(IDataAdapter reader, LoadOption overwriteChanges)
        {
            var ds = new DataSet(); //conn is opened by dataadapter

            reader.Fill(ds);
            return(ds.Tables[0]);
        }
Esempio n. 24
0
 public virtual DataSet GetDataSetAll(string sql, params Parameter[] parameters)
 {
     try
     {
         if (this.ProcessingEventStartingSQL != null)
         {
             ExecuteProcessingSQL(ref sql, parameters);
         }
         ExecuteBefore(sql, parameters);
         IDataAdapter dataAdapter = this.GetAdapter();
         IDbCommand   sqlCommand  = GetCommand(sql, parameters);
         this.SetCommandToAdapter(dataAdapter, sqlCommand);
         DataSet ds = new DataSet();
         dataAdapter.Fill(ds);
         if (this.IsClearParameters)
         {
             sqlCommand.Parameters.Clear();
         }
         ExecuteAfter(sql, parameters);
         return(ds);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         if (this.IsClose())
         {
             this.Close();
         }
     }
 }
Esempio n. 25
0
 /// <summary>
 ///  根据SQL语句字符串与数据库类型构造TsSet
 /// </summary>
 /// <param name="selectCommand"></param>
 /// <param name="dbType"></param>
 public TsSet(string selectCommand)
 {
     _dataAdapter = _database.GetAdapter(selectCommand);
     _dataSet     = new DataSet();
     _dataAdapter.Fill(_dataSet);
     TsDataTable = _dataSet.Tables[0];
 }
Esempio n. 26
0
 /// <summary>
 /// 执行查询语句,返回DataSet
 /// </summary>
 /// <param name="SQLString">查询语句</param>
 /// <returns>DataSet</returns>
 public DataSet ExecuteDataSet(string sqlString, CommandType cmdType, params IDataParameter[] iParms)
 {
     using (IDbConnection iConn = this.GetConnection())
     {
         IDbCommand iCmd = GetCommand();
         {
             PrepareCommand(out iCmd, iConn, null, sqlString, iParms);
             iCmd.CommandType = cmdType;
             try
             {
                 IDataAdapter iAdapter = this.GetAdapater(iCmd, iConn);
                 DataSet      ds       = new DataSet();
                 iAdapter.Fill(ds);
                 iCmd.Parameters.Clear();
                 return(ds);
             }
             catch (System.Exception ex)
             {
                 throw new Exception(ex.Message);
             }
             finally
             {
                 iCmd.Dispose();
                 if (iConn.State != ConnectionState.Closed)
                 {
                     iConn.Close();
                 }
             }
         }
     }
 }
Esempio n. 27
0
 /// <summary>
 /// 执行查询,并以DataView返回结果集
 /// </summary>
 /// <param name="Sql">SQL语句</param>
 /// <returns>DataView</returns>
 public DataView ExecuteDataView(string Sql)
 {
     using (IDbConnection iConn = this.GetConnection())
     {
         using (IDbCommand iCmd = GetCommand(Sql, iConn))
         {
             DataSet ds = new DataSet();
             try
             {
                 IDataAdapter iDataAdapter = this.GetAdapater(Sql, iConn);
                 iDataAdapter.Fill(ds);
                 return(ds.Tables[0].DefaultView);
             }
             catch (System.Exception e)
             {
                 throw new Exception(e.Message);
             }
             finally
             {
                 if (iConn.State != ConnectionState.Closed)
                 {
                     iConn.Close();
                 }
             }
         }
     }
 }
Esempio n. 28
0
 /// <summary>
 /// 执行查询语句
 /// </summary>
 /// <param name="SqlString">查询语句</param>
 /// <returns>DataTable </returns>
 public DataTable ExecuteDataTable(string SqlString, string Proc)
 {
     using (IDbConnection iConn = this.GetConnection())
     {
         using (IDbCommand iCmd = GetCommand(SqlString, iConn))
         {
             iCmd.CommandType = CommandType.StoredProcedure;
             DataSet ds = new DataSet();
             try
             {
                 IDataAdapter iDataAdapter = this.GetAdapater(SqlString, iConn);
                 iDataAdapter.Fill(ds);
             }
             catch (System.Exception e)
             {
                 throw new Exception(e.Message);
             }
             finally
             {
                 if (iConn.State != ConnectionState.Closed)
                 {
                     iConn.Close();
                 }
             }
             return(ds.Tables[0]);
         }
     }
 }
Esempio n. 29
0
 /// <summary>
 /// 执行查询语句
 /// </summary>
 /// <param name="SqlString">查询语句</param>
 /// <returns>DataTable </returns>
 public DataTable ExecuteDataTable(string sqlString)
 {
     using (IDbConnection iConn = this.GetConnection())
     {
         //IDbCommand iCmd  =  GetCommand(sqlString,iConn);
         DataSet ds = new DataSet();
         try
         {
             IDataAdapter iAdapter = this.GetAdapater(sqlString, iConn);
             iAdapter.Fill(ds);
         }
         catch (System.Exception e)
         {
             throw new Exception(e.Message);
         }
         finally
         {
             if (iConn.State != ConnectionState.Closed)
             {
                 iConn.Close();
             }
         }
         return(ds.Tables[0]);
     }
 }
Esempio n. 30
0
        /// <summary>
        /// Executes the Sql Command or Stored Procedure and return resultset in the form of DataSet.
        /// </summary>
        /// <param name="commandText">Sql Command or Stored Procedure name</param>
        /// <param name="commandType">Type of command (i.e. Sql Command/ Stored Procedure name/ Table Direct)</param>
        /// <returns>Result in the form of DataSet</returns>
        public DataSet ExecuteDataSet(string commandText, CommandType commandType)
        {
            DataSet       daReturn   = new DataSet();
            IDbConnection connection = _connectionManager.GetConnection();

            IDataAdapter adapter = (new DataAdapterManager()).GetDataAdapter(commandText, connection, commandType);

            try
            {
                adapter.Fill(daReturn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                    connection.Dispose();
                }
            }
            return(daReturn);
        }
Esempio n. 31
0
        /// <summary>
        /// 利用 DataAdapter 填充 DataSet
        /// </summary>
        /// <param name="adapter">用于填充 DataSet 的 Adapter 对象</param>
        /// <param name="dataSet">要被填充的 DataSet 对象</param>
        /// <returns>填充后的 DataSet 对象</returns>
        public static DataSet Fill( IDataAdapter adapter, DataSet dataSet )
        {
            if ( dataSet == null )
            dataSet = new DataSet();

              adapter.Fill( dataSet );

              return dataSet;
        }
 private void buttonReadDB_Click(object sender, EventArgs e)
 {
     if (connection != null)
     {
         try
         {
             dataSet = new DataSet();
             IDbCommand command = connection.CreateCommand();
             command.CommandText = string.Format("SELECT ID, IDENTIFICATION, KEYS, EN as Description FROM SYS_LANGUAGE WHERE IDENTIFICATION = '{0}'", ID);
             adapter = CreateDbDataAdapter(command);
             adapter.FillSchema(dataSet, SchemaType.Mapped);
             adapter.Fill(dataSet);
             dataGridView.DataSource = dataSet;
             dataGridView.DataMember = dataSet.Tables[0].TableName;
             dataGridView.Columns[0].Visible = false;
             dataGridView.Columns[1].Visible = false;
             dataSet.Tables[0].TableNewRow += delegate(object table, DataTableNewRowEventArgs dre)
             {
                 dre.Row["IDENTIFICATION"] = ID;
             };
             buttonWriteDB.Enabled = true;
             buttonRefresh.Enabled = true;
         }
         catch (Exception ex)
         {
             MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
        protected void LoadFromDataAdapter(IDataAdapter dataAdapter)
        {
            var dataSet = new DataSet();
            dataAdapter.Fill(dataSet);
            Data = dataSet.Tables[0];

            Log.Info("Data loaded.");

            for (var i = 0; i < Data.Columns.Count; i++)
            {
                var columnName = Data.Columns[i].ColumnName;
                var dataType = Data.Columns[i].DataType;
                Log.Info("Loaded column '{0}', data type '{1}'.", columnName, dataType != null ? dataType.Name : "unknown");

            }

            Log.Info("Data load complete. {0} rows loaded.", Data.Rows.Count);
        }