asp.net urgent request

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
if(reader.Read())
{
result = new Customer((string)reader["CustID"], (DateTime)reader["BirthDate"],
(string)reader["Name"], (string)reader["Sex"],
(short)reader["NameFormatCode"]);

}
 
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
 
You can test if the field is equal to System.DBNull.Value first. Or I think
Convert.ToString() might handle DBNull.
 
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

Back
Top