Solved

Passing Table-Valued Parameter (Computed Columns)

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

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Getting local user timezone in Sql Server 5 28
VB.NET - Refactor Class per SOLID principles 2 33
I need help adding validation to my MVC.Net view 6 21
vb.net sendkey 4 17
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

685 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