Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Error in trying to implicitly convert type 'Object' to '
Message
 
À
23/01/2005 17:21:34
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00979853
Message ID:
00979885
Vues:
12
Hi Bonnie. Thabks for your reply.
Regards,
Gerard


>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
>>
>>
>>
>>
>>
>>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform