Solved

Passing Table-Valued Parameter (Computed Columns)

Posted on 2014-12-29
2
52 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

919 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

16 Experts available now in Live!

Get 1:1 Help Now