I want to select items in listbox based on data reader contents from db. this is my code
mycmd = New OleDbCommand("SELECT PROD_MASTER.P_NAME FROM (PRO_APPROACH INNER JOIN PROD_MASTER ON PRO_APPROACH.P_ID = PROD_MASTER.P_ID) where PRO_APPROACH.VISIT_ID =" & sessionvar, cn)
dr = mycmd.ExecuteReader
Dim li As New ListItem
While dr.Read()
For i = 0 To dr.FieldCount - 1
' ListBox1.SelectedValue = dr("P_NAME")
li = ListBox1.Items.FindByText(dr("P_NAME").ToString())
If Not li.Equals(Nothing) = True Then
li.Selected = True
End If
Next
End While
dr.Close()
mycmd.Dispose()
where do i go wrong
I am getting error as obj ref not set to instance of obj... pls pls help me