I’m have little problem in retrieving the data from a table here’s the code: if the column in the db table is empty then the exception is thrown…
string cmdText = "select member_id,disp_id,mobile_no,tm,pm,lm,due_date from Recharge";
string UpdateStatus = "",hepUpdateStatus="";
OleDbCommand cmdFinalUpdate = new OleDbCommand(cmdText, conn);
OleDbDataReader updateReader = cmdFinalUpdate.ExecuteReader();
if (!updateReader.HasRows) // this condition is creating problem
MessageBox.Show("No Data Pending For Updation");
else
{
try
{
while (updateReader.Read())
{
Program.MemberID = Convert.ToInt64(updateReader.GetInt32(0));
Program.DispID = updateReader.GetString(1);
Program.Mobile = updateReader.GetString(2);
Program.Tm = updateReader.GetString(3);
Program.Pm = updateReader.GetString(4);
Program.Remarks = updateReader.GetString(5);
Program.DueDate = updateReader.GetString(6);
}
}
catch (Exception) { }
finally
{
updateReader.Close();
}
}
The Problem is, it is giving error on Forth Column i.e Program.Pm = updateReader.GetString(4); the error is specified cast is not valid (actually after the 3rd column it is giving exception) but im pretty sure that casting is not the issue, coz When i remove the if condtion at the top i.e if (!updateReader.HasRows) then the code works perfectly fine, i wanna know what is the problem with that reader if m checkin’ that reader has rows or not ?
From the GetString() documentation:
Looks like
Recharge.pmis not a string or contains a NULL value.