Pass single column of datatable to stored proc

AlHal2
AlHal2 used Ask the Experts™
on
I have a stored procedure which is expecting a data table with one column (user defined table type in SQL Server).
The data table has had to include an extra column, so the stored proc is failing due to the extra column.
How can I pass the first column of the data table to the stored proc.
I'm using C# in Visual Studio 2017.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Freelance programmer / Consultant
Commented:
Two possible things you could try:

You could modify the SP to expect two columns.  (The 'new' column is just ignored).

You also create a new DataTable in memory with the one column and copy the column contents from the two column table into this one column table and pass that into the SP - the SP is not modified in this case.
Doug BishopDatabase Developer

Commented:
There is no reason the stored proc should fail because the table has multiple columns or even because a column was added to the UDTT.. We pass user defined table types with 8-10 columns into stored procedures all the time with no problems. What is the syntax you are using in your ADO Command object to make the call to the procedure?
Doug BishopDatabase Developer

Commented:
Typically, a UDTT is populated in one stored procedure and then passed to a second procedure as a parameter. Are you attempting to populate the UDTT in your C# code and then passing it to a procedure to consume or are you using the first method?

Author

Commented:
I'm populating the UDTT in my C# code by calling one stored procedure.  I'm then passing the UDTT to a second stored procedure.
I need to amend the fist stored procedure to include a column required for filtering.  I can't amend the second stored procedure as it's used elsewhere.  Andy's suggestion has worked.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial