I’m using vb.net and sql server 2000 for developing my application….The problem i’m having is the Null Reference Exception on the Following line of code:
Dim cmd5 As New SqlCommand("select crtns_removed, pieces_removed, scheme from Outgoing_Invoice where invoice_no = '" & Me.ComboBox5.SelectedItem.ToString.Trim & "' And category = '" & Me.ComboBox1.SelectedItem.ToString.Trim & "' and item_name = '" & Me.ComboBox2.SelectedValue.ToString.Trim & "' and expiry_date = '" & Me.expiry_date.Text & "'", con)
I’m using this on the selectedindexchanged event of combobox1…The Code is on Return Stock form….But the exception is shown when I click the “Return Stock Button” on another form that will show the “Return Stock Form” but instead of showing the form it shows the exception on Combobox1 Selected Index changed event behind “Return Stock Form”
Can anyone help me out on this? Why is this issue arising and how can i get rid of it?
I would suggest validating each of the parameter values before defining the cmd5 command variable.
The problem is most likely that the index is not defined yet when the form is being openned for one or more of you comboboxes used for parameters in the SQL statement and thus they have do not have a value (NOTHING) and you and you are getting the exception.