Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > asp.net urgent request

Reply
Thread Tools

asp.net urgent request

 
 
=?Utf-8?B?YW1qYWQ=?=
Guest
Posts: n/a
 
      06-06-2006
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

 
Reply With Quote
 
 
 
 
Ray Booysen
Guest
Posts: n/a
 
      06-06-2006
Hi amjad

Would it be possible to post some code?

amjad wrote:
> 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
>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?YW1qYWQ=?=
Guest
Posts: n/a
 
      06-06-2006

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

}

"Ray Booysen" wrote:

> Hi amjad
>
> Would it be possible to post some code?
>
> amjad wrote:
> > 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
> >

>

 
Reply With Quote
 
=?Utf-8?B?YW1qYWQ=?=
Guest
Posts: n/a
 
      06-06-2006
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

"amjad" wrote:

> 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
>

 
Reply With Quote
 
Benjamin Strackany
Guest
Posts: n/a
 
      06-06-2006
You can test if the field is equal to System.DBNull.Value first. Or I think
Convert.ToString() might handle DBNull.

"amjad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>
> "amjad" wrote:
>
>> 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
>>



 
Reply With Quote
 
=?Utf-8?B?YW1qYWQ=?=
Guest
Posts: n/a
 
      06-07-2006
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

"amjad" wrote:

> 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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
URGENT RichA <rander3127@gmail.com> For rec.photo.digital MVP of all time. Vote now!! URGENT. Griffin Digital Photography 0 08-27-2010 08:18 AM
urgent help....need urgent help on say string task.. pooja Software 0 03-03-2009 06:16 AM
!!URGENT!! Tor Vulnerability Discovered !!URGENT!! Security Advisory Computer Security 1 08-11-2007 09:04 PM
URGENT !! QUEUE STL PROBLEM URGENT!! Sachin Jagtap C++ 4 04-29-2005 12:08 PM
Re: Accessing Request.InputStream / Request.BinaryRead *as the request is occuring*: How??? Brian Birtle ASP .Net 2 10-16-2003 02:11 PM



Advertisments