urgent asp.net invalid cast error

G

Guest

System.InvalidCastException: Specified cast is not valid.
hi i am received that error below is my code

result = new CustID(Convert.ToString(reader["CustID"]),
Line 57:
(DateTime)reader["BirthDate"],Convert.ToString(reader["Name"]),
Convert.ToString(reader["Sex"]), (Byte)reader["NameFormatCodeOri"],
Convert.ToString(reader["Address"]),
Convert.ToString(reader["PostCode"]));
First error was can not convert dbnull to string then i used
Convert.tostring and now i am getting that error not with all record but with
some records i assume dbnull value created some problem
thanks
 
W

Winista

If some of your fields can have null values then you need to check for
DbNull values before accessing those values. You can convert a null value.

If (!Convert.IsDBNull(dr[......])
{
... do your stuff ...
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Invalid cast? 2
Invalid cast! 0
Invalid parameter used error 0
cast musings 19
invalid parameter userd error....... 0
DbDataRecord Cast Error! 2
Question: Invalid Cast Exception Error 4
asp.net urgent request 5

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top