Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in Reading data rows through a OleDbDataReader

Status
Not open for further replies.

Susmita

Programmer
Jan 9, 2006
4
US
Dear Experts,
I am trying to execute a store procedure using the OleDbCommand.ExecuteReader() method. The stored proc returns 64 rows. Although, the program is successfully executing the stored proc, but it throws a runtime Null Reference exception after retrieving few rows. I am retrieving these rows through a OleDbDataReader object. The strange thing is that the program throws the exception randomly at any row. That is, sometime it fails while reading 8th row or sometime at 22nd row or 29th row.


OleDbCommand ObjCmd = new OleDbCommand(SPName, objConnect);
OleDbDataReader ResultSet;

ObjCmd.CommandType = CommandType.StoredProcedure;
ObjCmd.Parameters.Add(param); //param is an OleDbparameter object
ResultSet = ObjCmd.ExecuteReader();
while (ResultSet.Read())
{
Console.WriteLine("{0,25} {1,25:dd-MMM-yy} {2,25} {3,25:C}",ResultSet.GetString(0), ResultSet.GetDateTime(1), ResultSet.GetInt32(2), ResultSet.GetDecimal(3));
}
ResultSet.Close();



Pls. advise.

Thanks in advance,
Susmita
 
Just a small correction in my query.

It doesn't throw a Null Reference Exception, but Invalid Operation Exception - No data exists for the row/column.

Susmita
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top