Click here to Skip to main content
15,883,866 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi, Im reading data from the database using populate reader and the values that are type float don't want to display. i tried going through the code step by step but when it reaches type float the application stops, please help

C#
private void populate_report(Bank e, IDataReader dr)
{
   e.bank_id = dr.GetInt32(0);
   e.bankind_date = dr.GetString(1);
   e.r200 = dr.GetFloat(2);
   e.r100 = dr.GetFloat(3);
}
Posted
Comments
fjdiewornncalwe 1-Nov-12 10:59am    
Without knowing the exception that you are receiving, we really won't be able to help much. Could you please use the Improve Question widget and add that information to your question?
Chris Ross 2 1-Nov-12 11:02am    
It would also help if you included information about the Bank class - in particular the r200 and r100 property declarations.
If you went further to include information about the database data type of the columns that become items 2 and 3 in your data reader, that would also help.
Pete O'Hanlon 1-Nov-12 11:22am    
If the application is "stopping" at that point, it would suggest to me that the value isn't actually a float value in the database. What values are you getting there from the query, and what exception is being thrown?
DaveyM69 1-Nov-12 11:29am    
The remarks section says:
No conversions are performed. Therefore, the data retrieved must already be a single-precision floating point number.
Call IsDBNull to check for null values before calling this method.
I would start with those...
Sergey Alexandrovich Kryukov 1-Nov-12 12:50pm    
If could be anything. Actual data could be not of the type you expect; it could be text data, for example (varchar, etc.)...
--SA

1 solution

Try this,
C#
private void populate_report(Bank e, IDataReader dr)
{
   e.bank_id = dr.GetInt32(0);
   e.bankind_date = dr.GetString(1);

   if(! dr.IsDBNull(dr.GetDouble(2))
   {
     e.r200 = dr.GetDouble(2);
   }

   if(! dr.IsDBNull(dr.GetDouble(3))
   {
     e.r100 = dr.GetDouble(3);
   }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900