I've seen two common approaches for checking if a column exists in an IDataReader:
public bool HasColumn(IDataReader reader, string columnName)
{
try
{
reader.getOrdinal(columnName)
return true;
}
catch
{
return false;
}
}
Or:
public bool HasColumn(IDataReader reader, string columnName)
{
reader.G...
We all know that DataReaders are quicker than DataTables since the a DataReader is used in the construction of a DataTable.
Therefore given that I already have a DataTable.... Why would I want to convert it to a DataReader?
Well I am creating an internal interface called IDataProvider. This interface is intended to be implemented both ...
I want in the case of an empty data reader to output the field names with empty values.. ie
Product: -
Price: -
So, are IDataReader.GetName(i) and IDataReader.FieldCount safe to use when they have no results?
...
When you assign an active IDataReader object to either a Repeater, GridView, etc., does it automatically get closed upon completion of the DataBind method call or do we still need to explicitly close it ourselves?
this.sampleRepeater.DataSource = ExampleDAL.GetIDataReader();
this.sampleRepeater.DataBind();
...
Hello again,
I have a C# application over MySql, using MySQL Connector; I'm trying to make a
DataReader request, the query executes fine, however, when trying to access a DateTime field, i'm getting MySqlConversionException {"Unable to convert MySQL date/time value to System.DateTime"}
this is the prototype
if (dr != null && !dr.Read...
why My idatareader make error .....?
byteSize = _reader.GetBytes(_reader.GetOrdinal(sFieldName), 0, null, 0, 0);
I want to retrive image from database here sFieldName is database column Name......it show me Specified cast is not valid. message ......what i do?work on c# window vs05....
sFieldName is a string ....it's the column name...
i can not read image from database by idatareader can any one help me to read it?
...
The following post relates to the System.Data.SQLite data provider by phxsoftware (http://sqlite.phxsoftware.com)
I have a question (and possibly a problem) with DbDataReader’s Read method and/or Visual Studio 2008. In many examples I see things like the following (and I know this code doesn't make a lot of sense ... but it serves a pu...
I have a simple value object which I populate with data from an IDataReader (could be the result of a query to either an Oracle or MS SQL database). The factory method for this object looks something like the following:
internal static SomeClass CreateFromDataReader(IDataReader data)
{
string message = data.GetString(0);
short i...
I've been assigned on a project where the DAL consists of a base class with functions to return IDataReader, an Object (int, string and the like), or a DataSet. An ExecuteNonQuery function also exists. This DAL only accesses USPs (SQL Server), and is using MS's SqlHelper to execute the queries. Here's two sample functions from the base:
...
The way i currently populate business objects is using something similar to the snipet below.
using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.CDRDatabase))
{
using (SqlCommand comm = new SqlCommand(SELECT, conn))
{
conn.Open();
using (SqlDataReader r = comm.ExecuteReader(CommandBehavior...
Is there a way to see if a field exists in an IDataReader-based object w/o just checking for an IndexOutOfRangeException?
In essence, I have a method that takes an IDataReader-based object and creates a strongly-typed list of the records. In 1 instance, one data reader has a field that others do not. I don't really want to rewrite all...
I'm trying to fill a collection from an IDataReader that was returned by another method... for some reason it keeps throwing a "No parameterless constructor defined for this object." error for this line:
List<string> names = CBO.FillCollection<string>(DataProvider.Instance().ExecuteReader("getNames", new SqlParameter("UserId", 1)));
I...
What are the advantages of using a SQLDataReader as opposed to a reader that just implements IDatareader if I'm using SQL Server >= 2005?
Does the SQLDatareader simply have more functionality to choose from, or are there performance improvements using the SQLDatareader?
Any articles that discuss this would be appreciated.
Thanks!
Ch...
Hi all,
(LocalVariable)ABC.string(Name)= (Idatareader)datareader.GetString(0);
this name value is coming from database..
what happening here is if this name value is null while reading it's throwing an exception?
I am manually doing some if condition here. I don't want to write a manual condition to check all my variables..
I am doi...
I use IDataReader to call stored procedures without parameters. I am not finding examples of how to do this when parameters are present. Does IDataReader handle parameters of stored procedure?
Please provide an example.
...
Psuedo code for mapping configuration (as below) is not possible since the lambda only lets us access Type IDataReader, wheras when actually mapping, AutoMapper will reach into each "cell" of each IDataRecord while IDataReader.Read() == true:
var mappingConfig = Mapper.CreateMap<IDataReader, IEnumerable<MyDTO>>();
mappingConfig.ForMembe...