当前位置: 首页>>代码示例>>C#>>正文


C# DbCommand.ExecuteReader方法代码示例

本文整理汇总了C#中System.Data.Common.DbCommand.ExecuteReader方法的典型用法代码示例。如果您正苦于以下问题:C# DbCommand.ExecuteReader方法的具体用法?C# DbCommand.ExecuteReader怎么用?C# DbCommand.ExecuteReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.Common.DbCommand的用法示例。


在下文中一共展示了DbCommand.ExecuteReader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteSelectCommand

        public static DataTable ExecuteSelectCommand(DbCommand command)
        {
            DataTable table;

            try
            {
                command.Connection.Open();

                DbDataReader reader = command.ExecuteReader();

                table = new DataTable();
                table.Load(reader);

                reader.Close();
            }
            catch (Exception ex)
            {
                Utilities.LogError(ex);
                throw;
            }
            finally
            {
                command.Connection.Close();
            }

            return table;
        }
开发者ID:jdfosmark,项目名称:GiftShop,代码行数:27,代码来源:GenericDataAccess.cs

示例2: ExecuteReder

    public static IDataReader ExecuteReder(DbCommand command)
    {
        // The DataTable to be returned
        IDataReader rdr = null;
        // Execute the command making sure the connection gets closed in the end
        try
        {
            // Open the data connection
            command.Connection.Open();
            // Execute the command and save the results in a DataTable
            rdr = command.ExecuteReader();

            // Close the reader
            rdr.Close();
        }
        catch (Exception ex)
        {
            Utilities.LogError(ex);
            throw ex;
        }
        finally
        {
            // Close the connection
            command.Connection.Close();
        }
        return rdr;
    }
开发者ID:harshitshah436,项目名称:web-development,代码行数:27,代码来源:DataAccess.cs

示例3: ExecuteReader

        public IDataReader ExecuteReader(DbCommand command)
        {
            // check  method parameters
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            DbConnection connection = null;
            try
            {
                connection = GetOpenConnection();
                command.Connection = connection;

                var behavior = Transaction.Current == null ? CommandBehavior.CloseConnection : CommandBehavior.Default;

                return command.ExecuteReader(behavior);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                ReleaseConnection(connection);
                return null;
            }
        }
开发者ID:andipaetzold,项目名称:Ultimate-Festival-Organizer,代码行数:25,代码来源:Database.cs

示例4: ExecuteSelectCommand

    // executes a command and returns the results as a DataTable object
    public static DataTable ExecuteSelectCommand(DbCommand command)
    {
        // The DataTable to be returned
        DataTable table;
        // Execute the command making sure the connection gets closed in the end
        try
        {
            // Open the data connection
            command.Connection.Open();
            // Execute the command and save the results in a DataTable
            DbDataReader reader = command.ExecuteReader();
            table = new DataTable();
            table.Load(reader);

            // Close the reader
            reader.Close();
        }
        catch (Exception ex)
        {
            Utilities.LogError(ex);
            throw;
        }
        finally
        {
            // Close the connection
            command.Connection.Close();
        }
        return table;
    }
开发者ID:altras,项目名称:fmi_projects,代码行数:30,代码来源:GenericDataAccess.cs

示例5: ReadTable

 public static DataTable ReadTable(DbCommand cmd)
 {
     DataTable dt = new DataTable();
     DbDataReader reader = null;
     try
     {
         reader = cmd.ExecuteReader();
         int fieldc = reader.FieldCount;
         for (int i = 0; i < fieldc; i++)
         {
             DataColumn dc = new DataColumn(reader.GetName(i), reader.GetFieldType(i));
             dt.Columns.Add(dc);
         }
         while (reader.Read())
         {
             DataRow dr = dt.NewRow();
             for (int i = 0; i < fieldc; i++)
             {
                 dr[i] = reader[i];
             }
             dt.Rows.Add(dr);
         }
         return dt;
     }
     finally
     {
         if (reader != null) reader.Close();
     }
 }
开发者ID:503945930,项目名称:baoxin,代码行数:29,代码来源:HelperBase.cs

示例6: ExecuteCommand

        // executes a command and returns the results as a DataTable object
        public static DataTable ExecuteCommand(DbCommand command)
        {
            DataTable table;

            try
            {
                command.Connection.Open();

                DbDataReader reader = command.ExecuteReader();
                table = new DataTable();
                table.Load(reader);

                reader.Close();
            }
            catch (Exception exp)
            {
                //TODO: LogError
                throw exp;
            }
            finally
            {
                command.Connection.Close();
            }
            return table;
        }
开发者ID:jschefter,项目名称:UniversityChat,代码行数:26,代码来源:GenericDataAccess.cs

示例7: DisposingDbDataReader

 internal DisposingDbDataReader(DbCommand command)
 {
     if (command == null)
         throw new ArgumentNullException("command");
     this.command = command;
     reader = command.ExecuteReader(CommandBehavior.CloseConnection);
 }
开发者ID:radicalgeek,项目名称:Common,代码行数:7,代码来源:DisposingDbDataReader.cs

示例8: ExecuteReader

        public IDataReader ExecuteReader(DbCommand command)
        {
            var connection = new SQLiteConnection(_connectionString);
            command.Connection = connection;

            connection.Open();
            return command.ExecuteReader(CommandBehavior.CloseConnection);
        }
开发者ID:hotgazpacho,项目名称:TampaMVCHomework2,代码行数:8,代码来源:Database.cs

示例9: ExecuteResultInternal

 protected override object ExecuteResultInternal(IDbExecuteContext ctx, DbCommand command, Type resultType, object resultInstance)
 {
     using (var reader = command.ExecuteReader(CommandBehavior.SingleRow)) {
         if(reader.Read()) {
             resultInstance = this.ObjectMapper.Mapping(ctx.Statement, reader.ToDictionary(), resultType, resultInstance);
         }
         return resultInstance;
     }
 }
开发者ID:mer2,项目名称:devfx,代码行数:9,代码来源:SingleResultHandler.cs

示例10: ExecuteResultInternal

 protected override object ExecuteResultInternal(IDbExecuteContext ctx, DbCommand command, Type resultType, object resultInstance)
 {
     var defaultType = typeof(IDataReader);
     var type = this.GetResultType(ctx, resultType, resultInstance, defaultType);
     if (!defaultType.IsAssignableFrom(type)) {
         throw new DataException("要求返回的类型不正确");
     }
     return command.ExecuteReader(CommandBehavior.CloseConnection);
 }
开发者ID:mer2,项目名称:devfx,代码行数:9,代码来源:DataReaderResultHandler.cs

示例11: GetDataReader

 public static DbDataReader GetDataReader(DbCommand comando)
 {
     try
     {
         return comando.ExecuteReader();
     }catch(Exception e){
         MessageBox.Show("Erro ao retornar os valores " + e.Message + " " + e.Source, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return null;
     }
 }
开发者ID:FelipeOFF,项目名称:Secretaria,代码行数:10,代码来源:Connect.cs

示例12: ExecReader

        public DbDataReader ExecReader(DbCommand cm)
        {
            //OnExecuting(ExecTypes.Reader, cm);

            DbDataReader r = cm.ExecuteReader();

            //OnExecuted(ExecTypes.Reader, cm, null);

            return r;
        }
开发者ID:lepigocher,项目名称:simple-database,代码行数:10,代码来源:Db.Exec.cs

示例13: AsyncExecuteReader

        public virtual void AsyncExecuteReader(DbCommand cmd, Action<DbDataReader> readerHandler)
        {
            Require.IsNotNull("cmd", cmd);
            Require.IsNotNull("resultHandler", readerHandler);

            ThreadPool.QueueUserWorkItem(new WaitCallback((unused) =>
            {
                readerHandler(cmd.ExecuteReader());
            }));
        }
开发者ID:rreynolds-yp,项目名称:csharp-swift-consoleclient,代码行数:10,代码来源:DbProviderHelper.cs

示例14: ExecuteSelectCommand

        public static DataTable ExecuteSelectCommand(DbCommand command)
        {
            DataTable table;

            command.Connection.Open();
            DbDataReader reader = command.ExecuteReader();
            table = new DataTable();
            table.Load(reader);
            reader.Close();
            command.Connection.Close();

            return table;
        }
开发者ID:syedusamamazhar,项目名称:LeatherAppRepo,代码行数:13,代码来源:Catalog_Access.cs

示例15: ExecuteReader

 public static DbDataReader ExecuteReader(DbCommand cmd)
 {
     DbConnection connection = GetConnection();
     try
     {
         cmd.Connection = connection;
         return cmd.ExecuteReader(CommandBehavior.CloseConnection);
     }
     catch (Exception ex)
     {
         connection.Close();
         throw;
     }
 }
开发者ID:frksks,项目名称:SCV,代码行数:14,代码来源:DataHelper.cs


注:本文中的System.Data.Common.DbCommand.ExecuteReader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。