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


C# DbCommand.ExecuteReader方法代码示例

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


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

示例1: ExecuteReader

 public IDataReader ExecuteReader(DbCommand cmd)
 {
     DbConnection conn = null;
     try {
         conn = this.GetOpenConnection();
         cmd.Connection = conn;
         CommandBehavior behavior = this.IsSharedConnection() ? CommandBehavior.Default : CommandBehavior.CloseConnection;
         return cmd.ExecuteReader(behavior);
     } catch {
         ReleaseConnection(conn);
         throw;
     }
 }
开发者ID:ChristophWurst,项目名称:UFO,代码行数:13,代码来源:Database.cs

示例2: Query

 //----------------------------------------------------------------------------------------------------
 /// <summary>
 /// 쿼리 요청 ( SELECT )
 /// </summary>
 /// <param name="sql">SQL문</param>
 /// <returns>성공 유무</returns>
 //----------------------------------------------------------------------------------------------------
 public bool Query( string sql )
 {
     try
     {
         CloseQuery();
         m_command = m_connection.CreateCommand();
         m_command.CommandText = sql;
         m_reader = m_command.ExecuteReader();
         return true;
     }
     catch( Exception ex )
     {
         Log( ex.ToString() );
         m_error = ex.Message;
         CloseQuery();
         return false;
     }
 }
开发者ID:qipa,项目名称:BluemoonServer,代码行数:25,代码来源:cDatabase.cs

示例3: CreateDataReader

        /// <summary>
        /// Create a DataReader for the specified command.  
        /// <para>Please note that the associated connection is automatically closed when then datareader is closed.</para>
        /// </summary>
        public DbDataReader CreateDataReader(DbCommand cm)
        {
            DbConnection cn = cm.Connection;
            DbDataReader rd = null;

            errorMessage = "";
            try
            {
                if (cn.State != ConnectionState.Open)
                    cn.Open();
                rd = cm.ExecuteReader(CommandBehavior.CloseConnection);
                return rd;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                if (logEvents)
                    LogEvent("ERROR", cm.CommandText + "\r\n/\r\n" + ex.ToString());
                if (cn.State == ConnectionState.Open)
                    cn.Close();
                return null;
            }
        }
开发者ID:SyedMdKamruzzaman,项目名称:sap_interface,代码行数:27,代码来源:netlib7.cs

示例4: QueryReader

        /// <summary>
        /// Executes a command, and returns 1 row at a time until all rows are returned
        /// </summary>
        /// <param name="Command">The database command to execute the reader on</param>
        /// <returns></returns>
        public IEnumerable<Dictionary<string, object>> QueryReader(DbCommand Command)
        {
            // Increase Query Count
            NumQueries++;

            // Execute the query
            using (Command)
            using (DbDataReader Reader = Command.ExecuteReader())
            {
                // If we have rows, add them to the list
                if (Reader.HasRows)
                {
                    // Add each row to the rows list
                    while (Reader.Read())
                    {
                        Dictionary<string, object> Row = new Dictionary<string, object>(Reader.FieldCount);
                        for (int i = 0; i < Reader.FieldCount; ++i)
                            Row.Add(Reader.GetName(i), Reader.GetValue(i));

                        yield return Row;
                    }
                }

                // Cleanup
                Reader.Close();
            }
        }
开发者ID:roguesupport,项目名称:ControlCenter,代码行数:32,代码来源:DatabaseDriver.cs

示例5: ExecuteReader

        /// <summary>
        /// Executes a command, and returns the resulting rows
        /// </summary>
        /// <param name="Command">The database command to execute the reader on</param>
        /// <returns></returns>
        public List<Dictionary<string, object>> ExecuteReader(DbCommand Command)
        {
            // Execute the query
            List<Dictionary<string, object>> Rows = new List<Dictionary<string, object>>();
            DbDataReader Reader = Command.ExecuteReader();

            // If we have rows, add them to the list
            if (Reader.HasRows)
            {
                // Add each row to the rows list
                while (Reader.Read())
                {
                    Dictionary<string, object> Row = new Dictionary<string, object>(Reader.FieldCount);
                    for (int i = 0; i < Reader.FieldCount; ++i)
                        Row.Add(Reader.GetName(i), Reader.GetValue(i));

                    Rows.Add(Row);
                }
            }

            // Cleanup
            Reader.Close();
            Reader.Dispose();
            Command.Dispose();

            // Return Rows
            return Rows;
        }
开发者ID:JohannesHei,项目名称:ControlCenter,代码行数:33,代码来源:DatabaseDriver.cs

示例6: ExecuteReader

 public IDataReader ExecuteReader(DbCommand command)
 {
     DbConnection conn = GetOpenConnection();
     command.Connection = conn;
     CommandBehavior commandBehavior = IsSharedConnection() ? CommandBehavior.Default : CommandBehavior.CloseConnection;
     return command.ExecuteReader(commandBehavior);
 }
开发者ID:Ethon,项目名称:mcflurry_simulator,代码行数:7,代码来源:MYSQLDatabase.cs

示例7: DumpRecordsFromTable

        /// <summary>
        /// Dumps the result of a given SQL query into a tab separated file.
        /// </summary>
        /// <param name="command">The database to pull the data from.</param>
        /// <param name="query">The query to select the data with.</param>
        /// <param name="filename">The file to dump the results to.</param>
        private void DumpRecordsFromTable(DbCommand command, string query, string filename)
        {
            command.CommandText = query;
            using (StreamWriter writer = new StreamWriter($"migrate\\{filename}"))
            using (DbDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    for (int i = 0; i < reader.FieldCount; ++i)
                    {
                        if (i != 0)
                        {
                            writer.Write('\t');
                        }

                        object val = reader.GetValue(i);
                        writer.Write(val);
                    }

                    writer.WriteLine();
                }
            }
        }
开发者ID:marshl,项目名称:MtgJsonParser,代码行数:29,代码来源:Parser.cs

示例8: GetDataReader

 //metodo para retornar o leitor usado para ler os Selects usados
 public static DbDataReader GetDataReader(DbCommand comando)
 {
     return comando.ExecuteReader();
 }
开发者ID:GuilhermeGolfetto,项目名称:CSharpIntermediario,代码行数:5,代码来源:DAOUtils.cs

示例9: Select

        //Select statement
        public IDataReader Select(DbCommand select_query)
        {
            try
            {
                //Open connection
                if (this.OpenConnection() != null)
                {

                    //Create a data reader and Execute the command
                    IDataReader data_reader = select_query.ExecuteReader();

                    //return data reader so programmer can read results
                    return data_reader;
                }

            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
               return null;
        }
开发者ID:nkasozi,项目名称:Nkujukira,代码行数:23,代码来源:MySQLDataBaseHandler.cs

示例10: ReadTable

 public 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:rew170,项目名称:soomecode,代码行数:29,代码来源:MysqlDBHelper.cs

示例11: callStoredProcedure

 private DataTable callStoredProcedure(string name, List<DbParameter> parameters)
 {
     DataTable results ;
     command = connection.CreateCommand();
     command.CommandText = name;
     command.CommandType = CommandType.StoredProcedure;
     command.Parameters.AddRange(parameters.ToArray());
     command.Connection = connection;
     if (connection.State != ConnectionState.Open) { connection.Open(); }
     results = new DataTable();
     results.Load(command.ExecuteReader());
     return results;
 }
开发者ID:opensourceportfolio,项目名称:WebPortfolio,代码行数:13,代码来源:DataLayer.cs


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