simple understanding...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
Does anyone can explain please for what I should use:
(byte)dr["Building"]
and this:
Convert.ToByte(dr["Building"])

thanx,
Oren
 
(byte)dr["Building"]

In this case you are asumming the dr collection holds byte but it's
return type is something other than byte (typically object), so you know
the collection contains bytes but the compiler doesn't. The case (byte)
is telling the compiler that you know what you are doing, i.e. that dr
really does contain bytes and you want to retrieve one.
and this:
Convert.ToByte(dr["Building"])

In this case you don't know that the dr collection contains bytes, it
may contain a string retpresentation of a byte, so for example the value
of dr["building"] would be "2" rather than 2. In that case you have to
convert from a string "2" to a byte 2.

Hope that makes sense

Kevin
 
How about dr.GetByte(0); // where '0' is the index of the column

or int i = dr.GetOrdinal("Building");
byte b = dr.GetByte(i);

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

It takes a tough man to make a tender chicken salad.
 
Back
Top