本文整理汇总了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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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();
}
}
示例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;
}
示例7: DisposingDbDataReader
internal DisposingDbDataReader(DbCommand command)
{
if (command == null)
throw new ArgumentNullException("command");
this.command = command;
reader = command.ExecuteReader(CommandBehavior.CloseConnection);
}
示例8: ExecuteReader
public IDataReader ExecuteReader(DbCommand command)
{
var connection = new SQLiteConnection(_connectionString);
command.Connection = connection;
connection.Open();
return command.ExecuteReader(CommandBehavior.CloseConnection);
}
示例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;
}
}
示例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);
}
示例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;
}
}
示例12: ExecReader
public DbDataReader ExecReader(DbCommand cm)
{
//OnExecuting(ExecTypes.Reader, cm);
DbDataReader r = cm.ExecuteReader();
//OnExecuted(ExecTypes.Reader, cm, null);
return r;
}
示例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());
}));
}
示例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;
}
示例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;
}
}