asp.net urgent request

G

Guest

System.InvalidCastException: Unable to cast object of type 'System.Byte' to
type 'System.String'.

i am using sql serve 2005 and asp.net 1.1
i dont know why i am getting that error i am not uisng any byte type i have
three type of data in sql varcha datetime and tinyint....
any body have any idea how to reslove that problem as i am uisng sqlreader
to read the data and save it in local variables. thanks
 
G

Guest

if(reader.Read())
{
result = new Customer((string)reader["CustID"], (DateTime)reader["BirthDate"],
(string)reader["Name"], (string)reader["Sex"],
(short)reader["NameFormatCode"]);

}
 
G

Guest

I have solved that problem but another problem now i am facing is that DBNULL
cannot convert to string .. i am assuming some field values are null ... do
you have any idea to how to convert even if it has null value also thanks
 
B

Benjamin Strackany

You can test if the field is equal to System.DBNull.Value first. Or I think
Convert.ToString() might handle DBNull.
 
G

Guest

Yeah theoritically it should hand dbnull but i dont know with asp.net its not
doing that if any field contain dbnull data it gave me exception ..... its
bit headache any one know better way to do that thing . thanks
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top