Access Data

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have a 2 SQL procedures: the first one returns only a string. The
second one returns only a boolean value.

I created all my connection, parameters and command code.

What is the best way to read the returned string value, in first case,
or the returned boolean value, in second case?


My code is as follows:

1 ' Code that creates the connection, parameters, etc
2 ' ...
3
4 ' Execute the command
5 Dim value As DbDataReader = command.ExecuteReader()
6
7 ' ???? THE CODE I NEED TO KNOW
8
9 value.Close()
10 connection.Close()

Thanks,

Miguel
 
As stated above, the command.executescalar is ideal for this situation, you use it like this

dim bValue as boolean
Connection.open
bValue = command.executescalar
connection.close

If you where reading an integer then

dim intValue as integer
connection.open
intValue = command.executescalar
connection.close

ETC....
 
dim bValue as boolean
bValue = command.executescalar
dim intValue as integer
intValue = command.executescalar

Do you not need to explicitly cast the object datatype returned by
ExecuteScaler() in VB.NET...? You certainly do in C#...

Would the above code compile, even with Option Strict off...?
 
I did as follows:

Dim html As String = CType(command.ExecuteScalar, String)

Thanks,
Miguel
 
Dim html As String = CType(command.ExecuteScalar, String)

Yes, I thought you'd need to do something like that, since ExecuteScalar
returns an object type.
 
Back
Top