T Hoecherl
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is another option but querying the database twice is bad for overall performance!
ASKER
Port = cmd.ExecuteScalar()
Thanks.