I am tryign to return the values from a table based on the selected value of a combobox. This code is in a SelectedIndexChanged event of a combobox. If anyone could please read this code and tell me where my error is and point me the correct direction. I declare my variables, create a connection string and open.Dim strprocess As String Dim strpart As String = Nothing strprocess = cboprocess.SelectedValue Dim connectionString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\sql_dbf\kanban card.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" strpart = "SELECT PartNumber FROM tblParts WHERE Process = @Process" Dim conn1 As New SqlConnection(connectionString) conn1.Open()
Then I am using the next block of code (I think) to create a data table to hold the results of the query.Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(strpart) cmd.CommandType = CommandType.Text cmd.Parameters.AddWithValue("@Process", strprocess) cmd.Connection = conn1 Dim someDatatable As New DataTable Dim myReader As SqlClient.SqlDataReader = cmd.ExecuteReader If myReader.HasRows Then someDatatable.Load(myReader) End If
But when I try to compile I get an error:The parameterized query '(@Process nvarchar(4000))SELECT PartNumber FROM tblParts WHERE P' expects the parameter '@Process', which was not supplied.Thanks in advanced for any help.