title: VB.NET - Stored procedure runs but parameters aren't working
body: <p>I have the following bit of code:</p>
  
  <pre><code>Dim SQLCon As New SqlConnection
  Dim cmd As New SqlCommand
  Dim ds As New DataSet
  
  SQLCon.ConnectionString = ConfigurationSettings.AppSettings("myConnString")
  SQLCon.Open()
  cmd.CommandType = CommandType.StoredProcedure
  
  'run the stored procedure based on the view selected
  If rdolstView.Items(0).Selected Then
      cmd = New SqlCommand("spCondensedView", SQLCon)
  ElseIf rdolstView.Items(1).Selected Then
      cmd = New SqlCommand("spExtendedView", SQLCon)
  End If
  
  'filter by what the user searched for
  If ddlSearchBy.SelectedValue = "Member" Then
      cmd.Parameters.AddWithValue("@MbrNum", txtSearchFor.Text)
  ElseIf ddlSearchBy.SelectedValue = "Assistant" Then
      cmd.Parameters.AddWithValue("@AssignedAsst", ddlUWAssistants.SelectedValue)
  ElseIf ddlSearchBy.SelectedValue = "Rep" Then
      cmd.Parameters.AddWithValue("@Rep", txtSearchFor.Text)
  ElseIf ddlSearchBy.SelectedValue = "Dept Assistant" Then
      cmd.Parameters.AddWithValue("@DeptAsst", txtSearchFor.Text)
  ElseIf ddlSearchBy.SelectedValue = "Creator" Then
      cmd.Parameters.AddWithValue("@Creator", txtSearchFor.Text)
  End If
  
  Dim da As New SqlDataAdapter(cmd)
  da.Fill(ds)
  SQLCon.Close()
  </code></pre>
  
  <p>My problem is that the parameters don't seem to be working. Both stored procedures are supposed to take the optional parameter (either <code>@MbrNum</code>, <code>@AssignedAsst</code>, <code>@Rep</code>, <code>@DeptAsst</code>, or <code>@Creator</code>) and filter by it in its <code>WHERE</code> clause. </p>
  
  <p>I've confirmed that this is working properly when I run the stored procedures manually in SQL Server Management Studio. I've also confirmed that the <code>If</code>/<code>ElseIf</code> statements are validating as true properly. So my code is definitely hitting the <code>AddWithValue()</code> statements when it's supposed to.</p>
  
  <p>My returned result, however, is the full dataset without the filters applied, as if I ran the stored procedure with no parameters specified.</p>
  
  <p>Any help would be awesome. Thanks!</p>