Hi,
I have problem when trying to connect to databse and execute query.
Here is the full code:
Private Sub OpenDataReader()
Dim strConn As String = "Server=localhost;Database=Northwind;" + _
"Integrated Security=SSPI"
Dim cnnNwind As SqlConnection = New SqlConnection(strConn)
cnnNwind.Open()
Dim strSQL As String = "SELECT * FROM Shippers"
strSQL += "; SELECT EmployeeID,FirstName,LastName FROM Employees"
Dim cmdReader As SqlCommand = New SqlCommand(strSQL, cnnNwind)
cmdReader.CommandText = CommandType.Text
Dim sdrReader As SqlDataReader = cmdReader.ExecuteReader(CommandBehavior.CloseConnection)
'sdrReader = cmdReader.ExecuteReader
With sdrReader
If .HasRows Then
While .Read
lstShippers.Items.Add(.Item(0).ToString + " - " + .Item(1).ToString)
End While
While .NextResult
While .Read
lstEmployees.Items.Add(.Item(0).ToString + " - " + .Item(1).ToString + " " + .Item(2).ToString)
End While
End While
End If
.Close()
End With
End Sub
I get the message "Incorrect syntax near '1' " pointing to line where sdrReader is introduced.