Link to home
Start Free TrialLog in
Avatar of T Hoecherl
T HoecherlFlag for United States of America

asked on

VB.net capture result of a SQL query in variables

I have this code that launches a SQL Query:

        Dim Port As String
        Dim Host, Header, OrderNumber, LineNumber, Button As String

        Button = Screen.Name.ToString

        Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand
        cmd.Connection = cn
        cmd.CommandType = CommandType.Text
        cn.Open()
        cmd.CommandText = "SELECT PORT, HOST FROM PCT_LABEL_CONFIG WHERE NAME = '" & Button & "'"
        cmd.ExecuteNonQuery()

I want the values returned for PORT and HOST to be capture in vb.net variables.  How do I do that?
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of T Hoecherl

ASKER

Actually it turned out to be quite simple.  I just ran the query twice, extracting one of the two variables each time and then used this code:

Port = cmd.ExecuteScalar()

Thanks.
This is another option but querying the database twice is bad for overall performance!