title: Binding empty list or null value to table valued parameter on a stored procedure (.NET)
body: <p>I have created a stored procedure that takes a table valued parameter that is a table with a single column of type <code>int</code>.  The idea is to simply pass a list of ids into the store procedure and allow the stored procedure to work with the data.  However, in the case where there is no data to pass in, I am encountering problems (things work correctly when I have data).  I am converting a <code>List&lt;int&gt;</code> to an <code>IEnumerable&lt;SqlDataRecord&gt;</code>, and binding that to the table valued parameter for the stored procedure.  I have tried to bind an empty <code>List&lt;SqlDataRecord&gt;</code>, which resulted in the error:</p>
  <blockquote>
  <p>System.ArgumentException: There are no records in the SqlDataRecord enumeration. To send a table-valued parameter with no rows, use a null reference for the value instead.</p>
  </blockquote>
  <p>I then tried to bind a null value (which I thought was what the above message was getting at), but that only resulted in a different error message</p>
  <blockquote>
  <p>System.NotSupportedException: DBNull value for parameter '@MainItemIdList' is not supported. Table-valued parameters cannot be DBNull.</p>
  </blockquote>
  <p>It does not appear that you can declare the table valued parameter as nullable in the stored procedure declaration.  What is the correct method for binding an empty list to at table valued parameter?</p>