searchsanjaysharma
asked on
"Object reference not set to an instance of an object." How to correct this during combobox binding.
The error comes at bold line. I am binding state combo with district combo, i.e when any state is selected then only district should get selected.
Private Sub cmbstate_SelectedIndexChan ged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbstate.SelectedIndexChan ged
cmbstate.SelectedIndex = -1
If CType(cmbstate.SelectedIte m, DataRowView)("state").ToSt ring() <> "--Select State--" Then
binddistricts()
End If
End Sub
Public Function binddistricts()
s = "select distinct district from statedistrict where flag=1 and state='" & cmbstate.SelectedItem & "' order by district"
da = New SqlDataAdapter(s, con)
dt = New DataTable()
da.Fill(dt)
Dim newCustomersRow As DataRow = dt.NewRow()
newCustomersRow("district" ) = "--Select District--"
dt.Rows.InsertAt(newCustom ersRow, 0)
With cmbdistrict
.DisplayMember = "district"
.ValueMember = "district"
.DataSource = dt
End With
cmbdistrict.Refresh()
End Function
Private Sub cmbstate_SelectedIndexChan
cmbstate.SelectedIndex = -1
If CType(cmbstate.SelectedIte
binddistricts()
End If
End Sub
Public Function binddistricts()
s = "select distinct district from statedistrict where flag=1 and state='" & cmbstate.SelectedItem & "' order by district"
da = New SqlDataAdapter(s, con)
dt = New DataTable()
da.Fill(dt)
Dim newCustomersRow As DataRow = dt.NewRow()
newCustomersRow("district"
dt.Rows.InsertAt(newCustom
With cmbdistrict
.DisplayMember = "district"
.ValueMember = "district"
.DataSource = dt
End With
cmbdistrict.Refresh()
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok
ASKER