Re: SqlDataReader showing Empty columns until after error.
- From: "Phil H" <google@xxxxxxxxxxxxxxx>
- Date: 7 Dec 2006 13:39:56 -0800
Just had another thought
The return statement of your GetInt() function should be:
return reader[ColumnNum]
NOT Reader[ColumnName] as you have it above!
The casting error you are getting which is throwing the exception may
be the attempt to cast the string 'ColumnName' to an integer for
indexing (which should be *ColumnNum*).
That at least would explain why the Catch() doesn't show anything wrong
with the actual data in reader.
Am I right?
Phil H wrote:
I'm sure someone is going to ask, so here's the GetInt()
----------------------------------------------------------------------------------------------------------
public static int GetInt(IDataReader reader, string columnName)
{
int columnNum = reader.GetOrdinal(columnName);
if (reader.IsDBNull(columnNum))
{
return 0;
}
else
{
return (int)reader[columnName];
}
}
----------------------------------------------------------------------------------------------------------
Please forgive me if this is a dumb question but is there any
particular reason why you don't use:
return (int) reader.GetInt32(columnNum)
to read off what you expect to be a 4 byte integer?
.
- Follow-Ups:
- Re: SqlDataReader showing Empty columns until after error.
- From: lithoman
- Re: SqlDataReader showing Empty columns until after error.
- References:
- SqlDataReader showing Empty columns until after error.
- From: lithoman
- Re: SqlDataReader showing Empty columns until after error.
- From: Phil H
- SqlDataReader showing Empty columns until after error.
- Prev by Date: Re: .net Application Performance
- Next by Date: Re: Essential ASP.NET 2.0- resource
- Previous by thread: Re: SqlDataReader showing Empty columns until after error.
- Next by thread: Re: SqlDataReader showing Empty columns until after error.
- Index(es):
Relevant Pages
|