title: Error Invalid cast from 'System.String' to 'System.Byte[]' in C# calling stored procedure
body: <p>I have a dropdownlist that gets populated with a varbinary(256) column from SQL Server.  I send the selected value in this dropdownlist to a stored procedure, but I get the error </p>
  
  <blockquote>
    <p>Invalid cast from 'System.String' to 'System.Byte[]'. </p>
  </blockquote>
  
  <p>The C# code is calling a SP that runs this query to return the name and id to the dropdown list.</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT staffID, sAMAccountName,  (sn + ', ' + givenName) AS fullName
  FROM staff
  WHERE deleteEmployee = 'no' AND recordType = 'staff'
  ORDER BY sn
  </code></pre>
  
  <p>I add the parameter as below.</p>
  
  <pre><code>objCmd.Parameters.Add("@staffID", SqlDbType.Binary).Value = ddl_staff.SelectedItem.Value;
  </code></pre>
  
  <p>If I go into SQL and execute the SP like below, I get the expected results.  </p>
  
  <pre class="lang-sql prettyprint-override"><code>DECLARE @staffID varbinary(256)
  SELECT @staffID = staffID from staff where samaccountname = 'johndoe'
  EXECUTE stp_nho_status @staffID
  </code></pre>
  
  <p>What is happening to the data when it is run by the asp.net page; is it converted to a string in the dropdownlist value?  Do I have to convert it somehow?</p>