title: TVP - Failed to convert parameter value from a SqlParameter to a IEnumerable`1
body: <p>I am trying to create a general purpose function which can accept tvp. </p>
  
  <p>I am getting error 'Failed to convert parameter value from a SqlParameter to a IEnumerable`1.'</p>
  
  <pre><code>Dim param As New SqlParameter("@parName", GetTVP(lstDates))
  param.SqlDbType = SqlDbType.Structured
  sqlProvider.ExecuteNonQueryV2("sp_Save", CommandType.StoredProcedure, param)
  
                            ---------------------
  Public Function ExecuteNonQuery(ByVal spname As String, ByRef returnValue As Integer, ByVal  ParamArray parameterValues() As Object) As Integer
  
      Dim connection As SqlConnection = Nothing
      Dim transaction As SqlTransaction = Nothing
      Dim command As SqlCommand = Nothing
      Dim r As Integer = -1
  
      Try
  
          connection = New SqlConnection(myconnectionString)
          command = New SqlCommand(spname, connection)
          command.CommandType = CommandType.StoredProcedure
          connection.Open()
          SqlCommandBuilder.DeriveParameters(command)
          Me.SetParameters(command, parameterValues)
          transaction = connection.BeginTransaction()
          command.Transaction = transaction
          r = command.ExecuteNonQuery()
          transaction.Commit()
  
      Catch ex As Exception
  
      Finally
  
      End Try
  
      Return r
  
  End Function
                            ---------------------
  
  Private Sub SetParameters(ByVal cmd As SqlCommand, ByVal parameterValues() As Object)
      Dim i As Integer
      For Each param As SqlParameter In cmd.Parameters
          param.Value = parameterValues(i)
          i += 1
      Next
  End Sub
  </code></pre>
  
  <p><strong>ADDED</strong></p>
  
  <p>I have updated the code and take the "SqlCommandBuilder.DeriveParameters(command)" out and now passing parameter as a sqlparameter list. All works fine now :) </p>
  
  <p><strong><em>But i like to know why is it working when i have not defined the parameter type to SqlDbType.Structured ? Isn't it required?</em></strong></p>
  
  <pre><code>Dim par As New List(Of SqlParameter)
  par.Add(New SqlParameter("@parName", GetTVP(lstDates))
  
  ---------------
  
    connection = New SqlConnection(myconnectionString)
    command = New SqlCommand(spname, connection)
    command.CommandType = CommandType.StoredProcedure
    connection.Open()
    Me.SetParameters(command, parameterValues)
    transaction = connection.BeginTransaction()
    command.Transaction = transaction
    r = command.ExecuteNonQuery()
    transaction.Commit()
  </code></pre>