declaration expected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shekhardotnet
    New Member
    • Sep 2009
    • 1

    #1

    declaration expected

    below testing code gives an error "declaratio n expected"
    please suggest

    Code:
    Imports System.Data.SqlClient
    
    Public Class Form1
        Inherits System.Windows.Forms.Form
        'Create ADO.NET objects.
        Private myConn As SqlConnection
        Private myCmd As SqlCommand
        Private myReader As SqlDataReader
        Private results As String
        'Create a Connection object.
    'here i got error on myConn that is declaration expected
            myConn = New SqlConnection("Initial Catalog=Northwind;" & _
                    "Data Source=localhost;Integrated Security=SSPI;")
    
        'Create a Command object.
           myCmd = myConn.CreateCommand
            myCmd.CommandText = "SELECT FirstName, LastName FROM Employees"
    
        'Open the connection.
            myConn.Open()
    
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            myReader = myCmd.ExecuteReader()
            'Concatenate the query result into a string.
            Do While myReader.Read()
                results = results & myReader.GetString(0) & vbTab & _
         myReader.GetString(1) & vbLf
            Loop
            'Display results.
            MsgBox(results)
            'Close the reader and the database connection.
            myReader.Close()
            myConn.Close()
    
        End Sub
    End Class
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

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

    Comment

    Working...