Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error in trying to implicitly convert type 'Object' to '
Message
From
23/01/2005 17:21:34
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00979853
Message ID:
00979861
Views:
11
In addition to using Kevin's suggestion of the int.Parse() method, you could also do an explicit cast:
MyNum = (int)dr["num_nexta"];
In either case, if your column contains a DBNull.Value, it'll blow up with the "specified cast invalid" error, so be aware of the fact that you may have to test your data.

~~Bonnie

>Hi.
>I am trying to read a record form a table, and display the contents of one field. (There is only one row in the table..coming from a dataset)
>The field is type numeric.
>
>My code is:
>
>
>DataTable dt = this.dsIFNUM.Tables["IFNUM"];
>
>// Go to the first record on the table
>DataRow dr = dt.Rows[0];
>
>// Store field contents to a variable
>int MyNum;
>MyNum = dr["num_nexta"];
>MessageBox.Show(Convert.ToString(MyNum));
>
>
>I am getting a 'Cannot Implicitly convert type 'Object' to 'Int'
> on the MyNum = dr["num_nexta"] line
>I am trying to store the value of the num_nexta field into Mynum field
> and then display the contents
>
>Any help appreciated.
>
>Regards,
>Gerard
>
>
>
>
>
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform