Solved

Passing Table-Valued Parameter (Computed Columns)

Posted on 2014-12-29
2
59 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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