simple understanding...

G

Guest

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

thanx,
Oren
 
K

Kevin Jones

(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
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top