Do I really need to use IConvertible? 
Author Message
 Do I really need to use IConvertible?

I have the following two statements in my C# Web
Application...


GrdEcn.Items[0].Cells[0];


= "2002-215";

This is one of many parameters required by a stored
procedure I run.  If I run the second command, it works
fine.  If I run the first command, I will get the error,

"Exception Details: System.InvalidCastException: Object
must implement IConvertible."  

The field type in SQL Server is VARCHAR(10). Why does it
want me to implement IConvertible, and how do I use I
Convertible?  I tried using,


IConvertible.ToChar(GrdEcn.Items[0].Cells[0]);

..but I get the error...

Compiler Error Message: CS0120: An object reference is
required for the nonstatic field, method, or
property 'System.IConvertible.ToChar
(System.IFormatProvider)'

Microsoft seems to be short on examples...so if I could
have an example, I would appreciate it.

Thanks!

Scott Fox, MSCE-NT4

Any ideas?  



Mon, 13 Dec 2004 03:48:46 GMT  
 Do I really need to use IConvertible?


Quote:
> I have the following two statements in my C# Web
> Application...


> GrdEcn.Items[0].Cells[0];


> = "2002-215";

> This is one of many parameters required by a stored
> procedure I run.  If I run the second command, it works
> fine.  If I run the first command, I will get the error,

> "Exception Details: System.InvalidCastException: Object
> must implement IConvertible."

> The field type in SQL Server is VARCHAR(10). Why does it
> want me to implement IConvertible, and how do I use I
> Convertible?  I tried using,


> IConvertible.ToChar(GrdEcn.Items[0].Cells[0]);

> ..but I get the error...

> Compiler Error Message: CS0120: An object reference is
> required for the nonstatic field, method, or
> property 'System.IConvertible.ToChar
> (System.IFormatProvider)'

> Microsoft seems to be short on examples...so if I could
> have an example, I would appreciate it.

GrdEcn.Items[0].Cell[0] is of type DataGridCell.

Your Parameter is of type SqlDbType.VarChar (I assume).
You can assign it a String.

How could you convert a DataGridCell to a string?
DataGridCell would have to implement IConvertible
and implement the ToString or ToChar method.
If it doesn't do this, then .NET doesn't know how
to convert it from a Cell to a String.

You should put a ".ToString()" on the end of the
"Cell[0]" to resolve the matter.

-c



Mon, 13 Dec 2004 04:13:31 GMT  
 Do I really need to use IConvertible?
That did it!  I also had to insert ".Text" right before
the ".ToString()" in order to get the value of the field
returned (instead of "System.Web").

Thanks for your help!

Quote:
>-----Original Message-----





Quote:
>> I have the following two statements in my C# Web
>> Application...


>> GrdEcn.Items[0].Cells[0];


>> = "2002-215";

>> This is one of many parameters required by a stored
>> procedure I run.  If I run the second command, it works
>> fine.  If I run the first command, I will get the error,

>> "Exception Details: System.InvalidCastException: Object
>> must implement IConvertible."

>> The field type in SQL Server is VARCHAR(10). Why does it
>> want me to implement IConvertible, and how do I use I
>> Convertible?  I tried using,


>> IConvertible.ToChar(GrdEcn.Items[0].Cells[0]);

>> ..but I get the error...

>> Compiler Error Message: CS0120: An object reference is
>> required for the nonstatic field, method, or
>> property 'System.IConvertible.ToChar
>> (System.IFormatProvider)'

>> Microsoft seems to be short on examples...so if I could
>> have an example, I would appreciate it.

>GrdEcn.Items[0].Cell[0] is of type DataGridCell.

>Your Parameter is of type SqlDbType.VarChar (I assume).
>You can assign it a String.

>How could you convert a DataGridCell to a string?
>DataGridCell would have to implement IConvertible
>and implement the ToString or ToChar method.
>If it doesn't do this, then .NET doesn't know how
>to convert it from a Cell to a String.

>You should put a ".ToString()" on the end of the
>"Cell[0]" to resolve the matter.

>-c

>.



Mon, 13 Dec 2004 04:28:37 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Question: When is a CWinThread really done?

2. object must implement IConvertible

3. IConvertible Casting

4. System.InvalidCastException: Object must implement IConvertible.

5. Help w/ IConvertible

6. Update Object must implement IConvertible??

7. really really dumb question

8. I really really want to turn off warnings in eVC4 SP1

9. Really Easy Help needed Managed c++ syntax for declaring array of unsigned long

10. NEED HELP REALLY BAD

11. really need C++ help

12. I really need some help!

 

 
Powered by phpBB® Forum Software