K
Kini
Howdy!
Code
-----
string dtsSearchReq ="";
while (myReader.Read()) {
for(int j=0;j<myReader.FieldCount;j++) {
if (myReader.IsDBNull(i)) dtsSearchReq += myReader.GetString(i);
}
}
Background
----------
In the above code, I am using an OdbcDataReader to read the fields of
retrieved records. I am using a system DSN to connect to an MS-XL
spreadsheet.
There are 17 fields, 16 of which correspond to "string" datatype and 1
corresponds to "double". However, I would like to recieve all fields as
"string". One of the string fields in the database has a NULL value.
Problem
-------
When I use the IsDBNull check, myReader.GetString(i) fails at a field
with "double" datatype. System.InvalidCastException is raised. Note
that the "double" field contained a value of 1 and not a NULL.
When I do away with IsDBNull check, as expected, myReader.GetString(i)
fails when it encounters the NULL value. However, the "double" field
when encountered, is successfully converted to a corresponding text
representation (namely 1.00).
Summary: myReader.GetString(i) succesfully converts a "double" to
"string" in the absense of IsDBNull, but fails to do so in its
presence!
can anyone please throw some light?
Code
-----
string dtsSearchReq ="";
while (myReader.Read()) {
for(int j=0;j<myReader.FieldCount;j++) {
if (myReader.IsDBNull(i)) dtsSearchReq += myReader.GetString(i);
}
}
Background
----------
In the above code, I am using an OdbcDataReader to read the fields of
retrieved records. I am using a system DSN to connect to an MS-XL
spreadsheet.
There are 17 fields, 16 of which correspond to "string" datatype and 1
corresponds to "double". However, I would like to recieve all fields as
"string". One of the string fields in the database has a NULL value.
Problem
-------
When I use the IsDBNull check, myReader.GetString(i) fails at a field
with "double" datatype. System.InvalidCastException is raised. Note
that the "double" field contained a value of 1 and not a NULL.
When I do away with IsDBNull check, as expected, myReader.GetString(i)
fails when it encounters the NULL value. However, the "double" field
when encountered, is successfully converted to a corresponding text
representation (namely 1.00).
Summary: myReader.GetString(i) succesfully converts a "double" to
"string" in the absense of IsDBNull, but fails to do so in its
presence!
can anyone please throw some light?