Hello
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 SelectedIndexCh ange 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:
[code=vbnet]
Dim OLEConnect As System.Data.Ole Db.OleDbConnect ion = New System.Data.Ole Db.OleDbConnect ion(genCONNECTI ON)
Dim cmd As OleDbCommand = New OleDbCommand("s p_get_permissio ned_single_curv es", OLEConnect)
cmd.CommandType = CommandType.Sto redProcedure
Dim InputValue As OleDbParameter = cmd.Parameters. Add("@curvename ", OleDbType.VarCh ar, 50)
InputValue.Dire ction = ParameterDirect ion.Input
InputValue.Valu e = PersistedObject s.LoginUserName
Dim daCurveSetup As OleDbDataAdapte r = New OleDbDataAdapte r()
daCurveSetup.Se lectCommand = cmd
Dim dsCurveSetup = New DataSet("CurveS etup")
daCurveSetup.Fi ll(dsCurveSetup , "CurveSetup ")
'Add Data to the Curve Combo Box:
With cmbSingleCurven ame
.DataSource = dsCurveSetup.Ta bles("CurveSetu p")
.DisplayMember = "Curve_Name "
.ValueMember = "BaseCurve_Setu p_ID"
End With
'SelectedIndexC hange procedure code:
Private Sub cmbSingleCurven ame_SelectedInd exChanged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles cmbSingleCurven ame.SelectedInd exChanged
ContractNumber = Me.dsCurveSetup .Tables("CurveS etup").Rows(cmb SingleCurvename .SelectedIndex) .Item("Contract _ID")
With cmbContract_Nam e
.SelectedValue = ContractNumber
End With
End Sub
[/code]
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 SelectedIndexCh ange 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:
[code=vbnet]
Dim OLEConnect As System.Data.Ole Db.OleDbConnect ion = New System.Data.Ole Db.OleDbConnect ion(genCONNECTI ON)
Dim cmd As OleDbCommand = New OleDbCommand("s p_get_permissio ned_single_curv es", OLEConnect)
cmd.CommandType = CommandType.Sto redProcedure
Dim InputValue As OleDbParameter = cmd.Parameters. Add("@curvename ", OleDbType.VarCh ar, 50)
InputValue.Dire ction = ParameterDirect ion.Input
InputValue.Valu e = PersistedObject s.LoginUserName
Dim daCurveSetup As OleDbDataAdapte r = New OleDbDataAdapte r()
daCurveSetup.Se lectCommand = cmd
Dim dsCurveSetup = New DataSet("CurveS etup")
daCurveSetup.Fi ll(dsCurveSetup , "CurveSetup ")
'Add Data to the Curve Combo Box:
With cmbSingleCurven ame
.DataSource = dsCurveSetup.Ta bles("CurveSetu p")
.DisplayMember = "Curve_Name "
.ValueMember = "BaseCurve_Setu p_ID"
End With
'SelectedIndexC hange procedure code:
Private Sub cmbSingleCurven ame_SelectedInd exChanged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles cmbSingleCurven ame.SelectedInd exChanged
ContractNumber = Me.dsCurveSetup .Tables("CurveS etup").Rows(cmb SingleCurvename .SelectedIndex) .Item("Contract _ID")
With cmbContract_Nam e
.SelectedValue = ContractNumber
End With
End Sub
[/code]
Comment