Dataset read as integer?

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

Guest

i have a dataset with a few datatable inside.
most of my table are have values as in integer or double.

but everything i read my table out
e.g. "row.Item("ItemName").ToString

I always need to use the "ToString" method to read the entry out, which means
i need to convert it with Integer.Parse().....then store it to another
integer...then do calculation...then store it back to the datatable using the
ToString method again.
Theres just too many convertion!!

I am thinking is that a way to read out the value in datatable as a integer
straight away?

I tried using ".value", but it seems doesn't work, i cannot load it into an
integer or Double.

any ideas please! thankyou.
 
thanks!

Cor Ligthert said:
Jon,

The Items are object and should be with early binding be converted or
casted. I use in this case forever this (in the longest notation)

dim myresult as integer = CInt(ds.tables(0).rows(0).item(0))

Have a look at the type convert functions in VBNet, that is one of the
benefits upon other languages from VBNet that those are so powerfull.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vagrptypeconversion.asp

I hope this helps?

Cor
 
sorry Cor,1 more question, How good is cInt compare to Integer.Parse?
in performance and speed? because they both do the same thing right?
and i believe Convert.Int too... but i just wonder which is better in
performance wise as i have lots of conversion of integer and double variable.
 
Jon,

The convert functions are the adviced ones in VBNet. See this pages for this
and that as well for your other performance questions.

Do not think that functions in the Microsoft VisualBasic namespace extention
are slower than in the base Net namespace, for me it is what is the
functionality of such a function. The MVB Replace has by instance more
posibilities than the base replace. Here is the MVB replace slower than the
base one. The Find however is faster than the indexof, where the last has
more posibilities. But it is forever about nanoseconds or parts of that.

However I seldom (never) use MVB functions wherein is the index used. That
One index confuses me to much. But that is by instance not with the convert
functions.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchPerfOpt.asp

I hope this gives some ideas?

Cor
 
Back
Top