Using DataReader

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

Guest

After I execute my datareader, say for e.g. Reader = dbCommand.ExecuteReader,
I can do a while loop to retrieve the results, like this:
While Reader.Read()
Result = Reader.GetString(0)
End While

Say if the result returned is an Integer, what should I do? Reader.GetInt16?
32? 64? Which to choose? And should I declare my Result as Int16, Int32,
Int64 or Integer, i.e. Dim Result As Integer?

And say if the reader will contain only 1 row of result, and I don't want to
use a while loop to retrieve that only result, what can I do?

And also if I like to convert a String to a Integer type in ASP.NET codes
using Visual Basic (something like parseInt), what's the method?

Can someone help me? Thank you very much...
 
Wrytat,

When you place in the beginning of your message that you use VBNet you have
probably next time more proper response with this kind of questions about
datatypes.
Say if the result returned is an Integer, what should I do?
Reader.GetInt16?
32? 64? Which to choose? And should I declare my Result as Int16, Int32,
Int64 or Integer, i.e. Dim Result As Integer?

In VBNet for 32Bits Operating systems you use forever Integer when you don't
have to use for some reason another value types (The Integer is the standard
register value type from the used in 32Bits operating systems and therefore
the most optimized). This behaviour will change in W64 where it is not like
that)
And say if the reader will contain only 1 row of result, and I don't want
to
use a while loop to retrieve that only result, what can I do?

Use an executescalar instead of a datareader
http://msdn.microsoft.com/library/d...qlclientsqlcommandclassexecutescalartopic.asp
And also if I like to convert a String to a Integer type in ASP.NET codes
using Visual Basic (something like parseInt), what's the method?
\\\
If IsNumeric("1") Then
Dim myInt As Integer = CInt("1")
End If
///
Be aware on ASPNET that by instance a returned textbox can have all kind of
culture dependend values. The above sentence will probably fail (and when
not worser unwanted results) if the culture of the server is another than
the culture from the client. Probably is also better here to use a decimal
instead of an integer.

I hope this helps something,

Cor
 
Back
Top