Access Data

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
 
M

Mark Rae

A

Alexander Higgins

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....
 
M

Mark Rae

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...?
 
S

shapper

I did as follows:

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

Thanks,
Miguel
 
M

Mark Rae

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.
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top