I am new to VB.NET, so sorry if this is really obvious.
I have written the following code to fill my dataset from a stored procedure requiring 1 paramter input (from a SQL database). The Stored Procedure is quite lengthy including a number of inner joins.
The Dataset is used to populate a combobox on a form. I get the combobox to be populated by the dataset correctly based on my query selection. When the combobox selected item is changed, I want to return a value from the Dataset based on a row number (corresponding to the SelectedIndex from my ComboBox) given a Column Name within the dataset.
However, when I get to the SelectedIndexChange procedure the dataset is nothing, even though I have declared the variable as private within the form class (i.e. not within the set up procedure which creates the Dataset).
Code within initial procedure on loading the form:
Expand|Select|Wrap|Line Numbers
- Dim OLEConnect As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(genCONNECTION)
- Dim cmd As OleDbCommand = New OleDbCommand("sp_get_permissioned_single_curves", OLEConnect)
- cmd.CommandType = CommandType.StoredProcedure
- Dim InputValue As OleDbParameter = cmd.Parameters.Add("@curvename", OleDbType.VarChar, 50)
- InputValue.Direction = ParameterDirection.Input
- InputValue.Value = PersistedObjects.LoginUserName
- Dim daCurveSetup As OleDbDataAdapter = New OleDbDataAdapter()
- daCurveSetup.SelectCommand = cmd
- Dim dsCurveSetup = New DataSet("CurveSetup")
- daCurveSetup.Fill(dsCurveSetup, "CurveSetup")
- 'Add Data to the Curve Combo Box:
- With cmbSingleCurvename
- .DataSource = dsCurveSetup.Tables("CurveSetup")
- .DisplayMember = "Curve_Name"
- .ValueMember = "BaseCurve_Setup_ID"
- End With
- 'SelectedIndexChange procedure code:
- Private Sub cmbSingleCurvename_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSingleCurvename.SelectedIndexChanged
- ContractNumber = Me.dsCurveSetup.Tables("CurveSetup").Rows(cmbSingleCurvename.SelectedIndex).Item("Contract_ID")
- With cmbContract_Name
- .SelectedValue = ContractNumber
- End With
- End Sub