"Object reference not set to an instance of an object." How to correct this during combobox binding.
Posted on 2012-03-21
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_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbstate.SelectedIndexChanged
cmbstate.SelectedIndex = -1
If CType(cmbstate.SelectedItem, DataRowView)("state").ToString() <> "--Select State--" Then
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()
Dim newCustomersRow As DataRow = dt.NewRow()
newCustomersRow("district") = "--Select District--"
.DisplayMember = "district"
.ValueMember = "district"
.DataSource = dt