Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Coders,

I did a simple program to fill data by by the event ComboBox_SelectedIndexChanged in the code below. A Null error is happening unexpectedly. What will be the problem and Please Suggest me a solution. The Full code is below. And i also have a parameter called ms_no.

VB
Public Class Form1

    Private Sub E1BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles E1BindingNavigatorSaveItem.Click
        Me.Validate()
        Me.E1BindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.ProcurementDataSet)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'TODO: This line of code loads data into the 'ProcurementDataSet.Project' table. You can move, or remove it, as needed.
        Me.ProjectTableAdapter.Fill(Me.ProcurementDataSet.Project)
        'TODO: This line of code loads data into the 'ProcurementDataSet.E1' table. You can move, or remove it, as needed.
        Me.E1TableAdapter.Fill(Me.ProcurementDataSet.E1)

    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        Me.E1TableAdapter.FillBy(Me.ProcurementDataSet.E1, ms_no:=ComboBox2.SelectedValue)

    End Sub
End Class
Posted

1 solution

In your SelectedIndexChanged mejhandler, check that the SelectedValue is not null - if there is no selection (as will probably happen when the form loads) it will be null, at which point anything using it will throw the exception you refer to.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900