Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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.
 
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 10-Nov-12 21:17pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 DamithSL 285
1 Zoltán Zörgő 170
2 OriginalGriff 140
3 BillWoodruff 125
4 Sergey Alexandrovich Kryukov 120
0 OriginalGriff 7,740
1 DamithSL 5,769
2 Sergey Alexandrovich Kryukov 5,424
3 Maciej Los 5,076
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 11 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100