Solved

Passing Table-Valued Parameter (Computed Columns)

Posted on 2014-12-29
2
51 Views
Last Modified: 2015-05-14
Hello,

I have created a table valued parameter that’s works fine in SQL.  I’m now having trouble calling this from within a C# environment
Here is the type definition

CREATE TYPE ListTableStock AS TABLE (
item_number_concat varchar(10) NOT NULL, 
item_desc varchar(50), 
stock int NOT NULL,
item_number AS CAST( LEFT(item_number_concat, CHARINDEX('-', item_number_concat + '-') - 1) AS varchar(10) ),  --split out the item_number
ver AS CASE WHEN ISNUMERIC(CAST( SUBSTRING(item_number_concat,  CHARINDEX('-', item_number_concat + '-') + 1, 10) AS varchar(10) )) = 1 
THEN CAST( SUBSTRING(item_number_concat,  CHARINDEX('-', item_number_concat + '-') + 1, 10) AS varchar(10) )
ELSE NULL END
)

Open in new window


And here is the code that I use to call it

try
            {
                var cmd = new SqlCommand("get_item_id", connection)
                {
                    CommandType = CommandType.StoredProcedure
                };

                var ItemsList = new SqlParameter
                {
                    ParameterName = "@ItemsList",
                    Direction = ParameterDirection.Input,
                    TypeName = "ListTableStock",
                    Value = item_number_list,
                };


                cmd.Parameters.Add(ItemsList);

                connection.Open();
                var adapter = new SqlDataAdapter(cmd);
                adapter.Fill(allData);
                connection.Close();
            }
            catch (Exception ex)
            {
                connection.Close();
            }

Open in new window

The last two columns of the type are computed.  Therefore the SQL exception I’m getting is that I’m passing 3 into a type that requires 5 ?
I’m passing it a datable which contains the 2 columns – which match the non-computed ones?
Any idea if this is solvable?

Thanks.
0
Comment
Question by:andyw27
2 Comments
 
LVL 33

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 40521611
You have an extra coma at the end of

 Value = item_number_list,       line 13
0
 

Author Comment

by:andyw27
ID: 40521684
ah yeah, fixed that, prob still remains.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now