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.SqlC onnection( "user id=sa;password=admin;datab ase=Northw ind;server =192.168.1 1.118")
cmd = New SqlClient.SqlCommand
cmd.CommandText = "Select * from Customers"
cmd.Connection = cn
dr = cmd.ExecuteReader()
While dr.Read()
ListBox1.Items.Add(dr("Com panyName") )
End While
Catch ex As System.Data.SqlClient.SqlE xception
MessageBox.Show(ex.ToStrin g)
Finally
dr.Close()
cn.Close()
End Try
End Sub
Public Sub ReadSqlDataReader()
Dim cn As SqlClient.SqlConnection
Dim cmd As SqlClient.SqlCommand
Dim dr As SqlClient.SqlDataReader
Try
cn = New System.Data.SqlClient.SqlC
cmd = New SqlClient.SqlCommand
cmd.CommandText = "Select * from Customers"
cmd.Connection = cn
dr = cmd.ExecuteReader()
While dr.Read()
ListBox1.Items.Add(dr("Com
End While
Catch ex As System.Data.SqlClient.SqlE
MessageBox.Show(ex.ToStrin
Finally
dr.Close()
cn.Close()
End Try
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.