Link to home
Start Free TrialLog in
Avatar of CodeManiac
CodeManiac

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial