Problem with connection to SQL database

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2008
Posts: 32
Reputation: pete08 is an unknown quantity at this point 
Solved Threads: 0
pete08 pete08 is offline Offline
Light Poster

Problem with connection to SQL database

 
0
  #1
Apr 9th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 291
Reputation: ericstenson is an unknown quantity at this point 
Solved Threads: 29
Team Colleague
ericstenson's Avatar
ericstenson ericstenson is offline Offline
Posting Whiz in Training

Re: Problem with connection to SQL database

 
0
  #2
Apr 9th, 2008
Your trouble is not trouble accessing the database, it seems that is working just fine.

See MSDN

http://209.85.165.104/search?q=cache...lnk&cd=3&gl=us
--
"Dummy."
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC