SqlDataReader ExecuteReader error

What in the heck am I doing wrong!  I am building a pocket pc application.  I have a form the consists of: ListBox1 and Button1.  I would like to fill the list box with the CompanyName values from the NorthWind database.  I will trigger the  ReadSqlDataReader in the click event of Button1.  I keep getting an error from the dr = cmd.ExecuteReader code.  I am using the 2002 emulator.  I have been at this for hours without any result.  I know my connection string is correct.  



    Public Sub ReadSqlDataReader()


        Dim cn As SqlClient.SqlConnection
        Dim cmd As SqlClient.SqlCommand
        Dim dr As SqlClient.SqlDataReader

        Try
            cn = New System.Data.SqlClient.SqlConnection("user id=sa;password=admin;database=Northwind;server=192.168.11.118")
            cmd = New SqlClient.SqlCommand
            cmd.CommandText = "Select * from Customers"
            cmd.Connection = cn

            dr = cmd.ExecuteReader()

            While dr.Read()
                ListBox1.Items.Add(dr("CompanyName"))
            End While
        Catch ex As System.Data.SqlClient.SqlException
            MessageBox.Show(ex.ToString)
        Finally
            dr.Close()
            cn.Close()
        End Try
    End Sub
LVL 1
CodeManiacAsked:
Who is Participating?
 
Jeff CertainCommented:
Open the connection

cn = New System.Data.SqlClient.SqlConnection("user id=sa;password=admin;database=Northwind;server=192.168.11.118")
cn.open
cmd = New SqlClient.SqlCommand
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.