By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,230 Members | 2,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,230 IT Pros & Developers. It's quick & easy.

declaration expected

P: 1
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.  
Sep 27 '09 #1
Share this Question
Share on Google+
1 Reply


Plater
Expert 5K+
P: 7,872
Hmm, the code itself doesn't seem wrong, assuming that connection string is valid.
Sep 28 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.