Datatable dtProduto; (Filled)
int cdProduto = Convert.ToInt16(dtProduto.Rows[0]["cdProduto"]);
int cdReferencia = Convert.ToInt16(dtProduto.Rows[0]["cdReferencia"]);
The syntax dtProduto.Rows[i][Column] always returns an object, which one is the best way to convert’em to integers?
Regards, Jorge.
You’re currently converting them to what would be a “short” — or a 16-bit integer. I don’t think there’s anything wrong with the way you’re doing it now. Simply substitute
Convert.ToInt32()if you need a 32-bit Integer instead.If you aren’t sure what may be contained in your data source, you might want to be more careful about directly converting your source record data to concrete values by checking for nulls and/or parsing the result. Something like:
Substitute
shortforintif you do want 16-bit integers.