Using the data source wizard to create a data connection to a SQL database in VS2010. The following code was created:
Me.TblPartsTableAdapter.Fill(Me.KanbanDataSet.tblParts)
I assume ( probably wrongly) that since the text boxes and combobox that are bound to this database contain the correct data that a connection has been established and the dataset filled. So I want to query this data with a selected change event. I declare global variables
Dim strprocess As String
Dim strpart As String = Nothing
Then under the selected change event I use:
strprocess = cboprocess.SelectedValue
strpart = "SELECT PartNumber FROM tblParts WHERE Process = @Process"
Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(strpart)
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@Process", strprocess)
Dim someDatatable As New DataTable
Dim myReader As SqlClient.SqlDataReader = cmd.ExecuteReader
If myReader.HasRows Then
someDatatable.Load(myReader)
End If
The above code should take the selectedvalue of cboprocess put in the query and return a value to strpart. Then I will bind the results to cbopartnmber. When running the code I receive this error:
ExecuteReader: Connection property has not been initialized.
I think generally this means the connection is not open but itf its not open how is there data in the dataset. Is the datasource wizard a big POS?