0

I have a List<> object which I have to pass to a stored procedure in SQL Server 2008 as a table valued parameter. Here is the code:

List<someType> listObjects = new List<someType>();
//Fill listObjects
...
...
...
sqlcmd.Parameters.AddWithValue("@myTableValuedParameter",listObjects).SqlDbType = SqlDbType.Structured;
sqlcmd.ExecuteNonQuery();

Code is throwing an exception which says:

Object must implement IConvertible.

In past,I have successfully passed a DataTable as a table valued parameter. Structure of type of object someType is same as custom Type which I created in Sql Server.

What am I missing here and what changes do I need to include to make it run sucessfully

1
  • convert your list<> to type DataTable? as they are different stuff. Commented Dec 10, 2013 at 5:14

2 Answers 2

2

There are 3 things that can be passed as a Table Value Parameter:

  • IEnumerable<SqlDataRecord>
  • DataTable
  • DbDataReader

Your list, unless it contains SqlDataRecord cannot be used

Table-Valued Parameters

System.Data.SqlClient supports populating table-valued parameters from DataTable, DbDataReader or System.Collections.Generic.IEnumerable ([T:System.Collections.Generic.IEnumerable`1)] objects.

Sign up to request clarification or add additional context in comments.

Comments

0

Per the Table-Valued Parameters documentation only DataTable, DbDataReader or IEnumerable<SqlDataRecord> are supported:

System.Data.SqlClient supports populating table-valued parameters from DataTable, DbDataReader or System.Collections.Generic.IEnumerable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.