title: An OleDbParameter with ParameterName is not contained by this OleDbParameterCollection
body: <p>Very simple form like a dozen others I've made for internal tools, but this one kicks back the error "An OleDbParameter with ParameterName '@lookup' is not contained by this OleDbParameterCollection."</p>
  
  <p>The only difference, and it's probably the key to this, but I'm afraid I don't know the answer, is the connection string. I have been using a SQL 2008 server on a Windows 2008 R2 server so I my connection string has been easily configured in my Visual Studio 2008 like below:</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="DatasourceName" connectionString="server=servername;database=databasename;user=username;password=password;" providerName="System.Data.SqlClient"/&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>However, I'm still using VS 2008 but I'm connecting to a SQL 2012 server for my datasource so I had to change the connection string to:</p>
  
  <pre><code>    &lt;connectionStrings&gt;
          &lt;add name="server2012name" connectionString="Provider=SQLNCLI11.1;Data Source=ServerName;Persist Security Info=True;Password=password;User ID=userid;Initial Catalog=catalog"
          providerName="System.Data.OleDb" /&gt;
      &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>So since I've never seen this error, I wonder if the code I'm using does not work with an oledb connection for some reason. The offending piece of code is in the codebehind:</p>
  
  <pre><code>    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
  {
      e.Command.Parameters["@lookup"].Value = lookup.Text.ToString();
  
  }
  </code></pre>
  
  <p>Here is the ASPX code:</p>
  
  <pre><code>&lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
          ConnectionString="&lt;%$ ConnectionStrings:MyString %&gt;" 
          ProviderName="&lt;%$ ConnectionStrings:MyString.ProviderName %&gt;" 
          SelectCommand="SELECT [Beneficiary First Name] AS firstname
                              ,[Beneficiary Last Name] AS lastname
                              ,[Beneficiary Date of Birth] AS dob
                              ,[Address Line 1] AS [address]
                              ,[Beneficiary Encounter Date] AS encdate
                              ,[Beneficiary Data Sharing Preference Code] AS shareprefcode
                              ,[Beneficiary Data Sharing Decision Mechanism Code] AS decmechcode
                              ,[Beneficiary Alcohol and Drug Treatment Data Sharing Mechanism Co] AS damechcode
                              ,[MRN]
                              ,[Beneficiary HICN] AS hicn
                         FROM [database].[dbo].[table]
                         WHERE [MRN] = @lookup"
  
             onselecting="SqlDataSource1_Selecting"
             &gt;
           &lt;SelectParameters&gt;
               &lt;asp:Parameter Name="lookup" /&gt;
           &lt;/SelectParameters&gt;
           &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>Do I need some other assembly included? Do I use a different command to add that parameter?</p>
  
  <p>I've Googled this for hours and read through what I found, but none of it seemed to pertain to this. If I commend this e.Command.Parameters line out, the error goes away, but the query won't return anything. </p>
  
  <p>Thanks so much for any guidance.</p>
  
  <p>EDIT
  Unfortunately, it looks like this one's going to go unanswered. I'll add a little more here in case someone who knows what this is all about comes along.</p>
  
  <p>I've been reading all about OleDbParameters and that seems to be roughly the right track. I've changed the codebehind to about 50 variations of this:</p>
  
  <pre><code>    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
  {
      OleDbParameter fnParam = new OleDbParameter("@lookup", OleDbType.VarChar, 20);
      fnParam.Value = lookup.Text;
      e.Command.Parameters.Add(fnParam);
  }
  </code></pre>
  
  <p>And I have managed to move past the original error. I've changed the ASPX to remove the parameter declaration, no go. I've changed the parameter in the SQL query to a question mark, no go. At this point, I get no error or message of any kind. In my SQL Profiler trace, it's not hitting the SQL server at all. It's just not doing anything.</p>
  
  <p>In some of my variations, it actually gave me errors for data type mismatches, but I never could figure out how to alter the textbox value to be the right kind of data type for the OleDbType.</p>