L
Lezza
I found a lot of posters asking the following question,
but no answer? *Frustrated at the SQL PASS Convention*
Okay, SQL Database using SQLDataAdapter and a DataTable.
I've got one form with two ComboBoxes. On Form Load, I
fill da with a SELECT SPROC and populate ComboBox1. Works
great.
Now, I need to take SelectedValue from ComboBox1, and pass
it as a parameter on SelectedIndexChanged event to another
SPROC which will fill da and populate ComboBox2. On Debug,
I'm getting 'System.InvalidCastException' which leads me
to believe I'm not returning any values on da.Fill.
Following Code:
Private Sub cmbPersonalityTypeSP1_SelectedIndexChanged
(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles
cmbPersonalityTypeSP1.SelectedIndexChanged
'Create Connection String
Dim con As New SqlConnection("Data Source=
(local);Initial Catalog=StoryBook;Integrated
Security=True")
'Create New DataTable for Results Set
Dim dsPersTrait As New DataTable
'Create variable to hold sproc command
Dim cmd As New SqlCommand("c_GetMainTrait", con)
' Create a data adapter and pass in the SQL
statement and connection reference
Dim da As New SqlDataAdapter(cmd)
'Tell Object it is a SPROC
cmd.CommandType = CommandType.StoredProcedure
' Fill Parameter Value from ComboBox
cmd.Parameters.Add(New SqlParameter
("@TraitTypeID", SqlDbType.Int)).Value = _
cmbPersonalityTypeSP1.SelectedValue
da.SelectCommand.Connection.Open()
'Fill Dataset
da.Fill(dsPersTrait) <--ERROR Occurs HERE
da.SelectCommand.Connection.Close()
' Set the combo box data source to our datatable
cmbTraitSP1.DataSource = dsPersTrait
' Set the display value for the combobox to be the
column to be displayed
cmbTraitSP1.DisplayMember = "Trait"
' Set the id value for the combobox
cmbTraitSP1.ValueMember = "TraitID"
End Sub
but no answer? *Frustrated at the SQL PASS Convention*
Okay, SQL Database using SQLDataAdapter and a DataTable.
I've got one form with two ComboBoxes. On Form Load, I
fill da with a SELECT SPROC and populate ComboBox1. Works
great.
Now, I need to take SelectedValue from ComboBox1, and pass
it as a parameter on SelectedIndexChanged event to another
SPROC which will fill da and populate ComboBox2. On Debug,
I'm getting 'System.InvalidCastException' which leads me
to believe I'm not returning any values on da.Fill.
Following Code:
Private Sub cmbPersonalityTypeSP1_SelectedIndexChanged
(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles
cmbPersonalityTypeSP1.SelectedIndexChanged
'Create Connection String
Dim con As New SqlConnection("Data Source=
(local);Initial Catalog=StoryBook;Integrated
Security=True")
'Create New DataTable for Results Set
Dim dsPersTrait As New DataTable
'Create variable to hold sproc command
Dim cmd As New SqlCommand("c_GetMainTrait", con)
' Create a data adapter and pass in the SQL
statement and connection reference
Dim da As New SqlDataAdapter(cmd)
'Tell Object it is a SPROC
cmd.CommandType = CommandType.StoredProcedure
' Fill Parameter Value from ComboBox
cmd.Parameters.Add(New SqlParameter
("@TraitTypeID", SqlDbType.Int)).Value = _
cmbPersonalityTypeSP1.SelectedValue
da.SelectCommand.Connection.Open()
'Fill Dataset
da.Fill(dsPersTrait) <--ERROR Occurs HERE
da.SelectCommand.Connection.Close()
' Set the combo box data source to our datatable
cmbTraitSP1.DataSource = dsPersTrait
' Set the display value for the combobox to be the
column to be displayed
cmbTraitSP1.DisplayMember = "Trait"
' Set the id value for the combobox
cmbTraitSP1.ValueMember = "TraitID"
End Sub