Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 622
  • Last Modified:

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
0
CodeManiac
Asked:
CodeManiac
1 Solution
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now