V
Vibhu Srinivasan
I am using data reader for reading tables.
I have some issues with ADO readers, having come from a
java perspective
When reading a table say Account table ( which has two
fields Id(int), Name(varchar)) both can be null
In the C# code i end up doing
int id = (int)reader["Id"];
string name = (string)reader["Name"];
1) If the id or name Name is NULL this blows up with a ull
pointer . So i have to
int columnNum =
reader.GetOrdinalcolumnName);
if(reader.IsDBNull(columnNum)){
then read the column.
}
This int is a value type , how can i represent a NULL
object in the system. Is there a equivalent int object(
something like the Integer class in java to represent a
NULL value.
2) Is there a way to set up reader to retutn a DBNull
object if there are null values in the database.
What i ideally want to do is
reader.GetInteger("ColumnName"){
}
that returns a Integer and similarly reader.SetInteger
(Integer){
}
like i can easily do in the Java world.
Not quite sure why this was left out in .NET
Appreciate any feedback
Vibhu Srinivasan
I have some issues with ADO readers, having come from a
java perspective
When reading a table say Account table ( which has two
fields Id(int), Name(varchar)) both can be null
In the C# code i end up doing
int id = (int)reader["Id"];
string name = (string)reader["Name"];
1) If the id or name Name is NULL this blows up with a ull
pointer . So i have to
int columnNum =
reader.GetOrdinalcolumnName);
if(reader.IsDBNull(columnNum)){
then read the column.
}
This int is a value type , how can i represent a NULL
object in the system. Is there a equivalent int object(
something like the Integer class in java to represent a
NULL value.
2) Is there a way to set up reader to retutn a DBNull
object if there are null values in the database.
What i ideally want to do is
reader.GetInteger("ColumnName"){
}
that returns a Integer and similarly reader.SetInteger
(Integer){
}
like i can easily do in the Java world.
Not quite sure why this was left out in .NET
Appreciate any feedback
Vibhu Srinivasan