Connecting Tech Pros Worldwide Help | Site Map

declaration expected

Newbie
 
Join Date: Sep 2009
Posts: 1
#1: Sep 27 '09
below testing code gives an error "declaration expected"
please suggest

Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2.  
  3. Public Class Form1
  4.     Inherits System.Windows.Forms.Form
  5.     'Create ADO.NET objects.
  6.     Private myConn As SqlConnection
  7.     Private myCmd As SqlCommand
  8.     Private myReader As SqlDataReader
  9.     Private results As String
  10.     'Create a Connection object.
  11. 'here i got error on myConn that is declaration expected
  12.         myConn = New SqlConnection("Initial Catalog=Northwind;" & _
  13.                 "Data Source=localhost;Integrated Security=SSPI;")
  14.  
  15.     'Create a Command object.
  16.        myCmd = myConn.CreateCommand
  17.         myCmd.CommandText = "SELECT FirstName, LastName FROM Employees"
  18.  
  19.     'Open the connection.
  20.         myConn.Open()
  21.  
  22.  
  23.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  24.         myReader = myCmd.ExecuteReader()
  25.         'Concatenate the query result into a string.
  26.         Do While myReader.Read()
  27.             results = results & myReader.GetString(0) & vbTab & _
  28.      myReader.GetString(1) & vbLf
  29.         Loop
  30.         'Display results.
  31.         MsgBox(results)
  32.         'Close the reader and the database connection.
  33.         myReader.Close()
  34.         myConn.Close()
  35.  
  36.     End Sub
  37. End Class
  38.  
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,156
#2: Sep 28 '09

re: declaration expected


Hmm, the code itself doesn't seem wrong, assuming that connection string is valid.
Reply

Tags
shekhardotnet


Similar .NET Framework bytes