Share via


Mismatch between passed table valued parameter and User-defined table type

Question

Wednesday, September 15, 2010 9:47 AM

I have created a user define Table Type with two columns viz. Id and Value (both are nullable). Now from my application I am passing a datatable with only one column and the column name is "Id".

My expectation was it would populate only the "Id" column with the values and keep the "Value" column NULL. 

But I am getting an error stating "Trying to pass a table valued parameter with 1 column(s) where the corresponding user-defined table type requires 2 column(s).

Is it possible to pass a one column datatable as a parameter to the 2 column user defined table type.

Regards, digital
Success is 3-D coz it demands Desire, Determination and Dedication.

All replies (1)

Monday, September 27, 2010 8:47 PM

You will need to create a new Strongly-Typed DataTable and then use its Merge function, as this can handle missing schema information (such as a missing column): http://msdn.microsoft.com/en-us/library/system.data.datatable.merge.aspx