<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: SQL Server 2008 Table Valued Parameters</title>
	<atom:link href="http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/</link>
	<description>Do it in .Net way &#124; Blogging about C#,ASP.Net, LINQ,WPF and .Net Technologies</description>
	<lastBuildDate>Wed, 17 Feb 2010 13:44:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Adam</title>
		<link>http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/comment-page-1/#comment-398</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Tue, 01 Dec 2009 20:05:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/#comment-398</guid>
		<description>I know this is an old comment string and an even older article, but the solution si simply to not insert into the identity column. 

INSERT INTO @InputFile(strRow) VALUES (‘A3&#124;BB&#124;C&#124;DDD’)

If this is the first record in the table it will populate with 1. If you then ran this a second time you would get a second row inserted with the same &quot;strRow&quot; value, but a 2 in the &quot;numCols&quot; column. The identity values need to be left out of the stored proc inserting into the table. If they need to be added you would have to do the part of setting identity insert off/on for the run. The tablein your code would not even need the identity column included.</description>
		<content:encoded><![CDATA[<p>I know this is an old comment string and an even older article, but the solution si simply to not insert into the identity column. </p>
<p>INSERT INTO @InputFile(strRow) VALUES (‘A3|BB|C|DDD’)</p>
<p>If this is the first record in the table it will populate with 1. If you then ran this a second time you would get a second row inserted with the same &#8220;strRow&#8221; value, but a 2 in the &#8220;numCols&#8221; column. The identity values need to be left out of the stored proc inserting into the table. If they need to be added you would have to do the part of setting identity insert off/on for the run. The tablein your code would not even need the identity column included.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aneef Fashir</title>
		<link>http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/comment-page-1/#comment-166</link>
		<dc:creator>Aneef Fashir</dc:creator>
		<pubDate>Tue, 16 Jun 2009 11:59:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/#comment-166</guid>
		<description>Ryan,

Try doing this in your SQL Statement:


&lt;blockquote&gt;SET IDENTITY_INSERT  ON

at the beginning of your SQL and

SET IDENTITY_INSERT  OFF&lt;/blockquote&gt;



because if you read the following : it seems we need to set this for each session of update when we use table valued parameters, and Identity columns. update me if it works. I haven&#039;t tested it as I&#039;M at work right now. 

http://msdn.microsoft.com/en-us/library/bb675163.aspx
Thanks</description>
		<content:encoded><![CDATA[<p>Ryan,</p>
<p>Try doing this in your SQL Statement:</p>
<blockquote><p>SET IDENTITY_INSERT  ON</p>
<p>at the beginning of your SQL and</p>
<p>SET IDENTITY_INSERT  OFF</p></blockquote>
<p>because if you read the following : it seems we need to set this for each session of update when we use table valued parameters, and Identity columns. update me if it works. I haven&#8217;t tested it as I&#8217;M at work right now. </p>
<p><a href="http://msdn.microsoft.com/en-us/library/bb675163.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/bb675163.aspx</a><br />
Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Daulton</title>
		<link>http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/comment-page-1/#comment-165</link>
		<dc:creator>Ryan Daulton</dc:creator>
		<pubDate>Tue, 16 Jun 2009 10:43:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/#comment-165</guid>
		<description>Thanks Aneef,

But is there any way to have identity column autoincrement without me changing IDENTITY_INSERT?  Otherwise, how do i get the IDENTITY_INSERT value to remain on? 
I tried setting the IDENTITY_INSERT to ON from SQL Management Studio:
&quot;
SET IDENTITY_INSERT ParentTable ON
GO
DECLARE @InputFile parseInputFile
INSERT INTO @InputFile(NumCols, strRow) VALUES (1, &#039;A3&#124;BB&#124;C&#124;DDD&#039;)
select * from @InputFile
&quot;
But then compiler returned following error:

&quot;
Msg 1077, Level 16, State 1, Line 2
INSERT into an identity column not allowed on table variables.
&quot;

And this is using same table UDT, parseInputFile, which is defined as:
&quot;
CREATE TYPE [dbo].[parseInputFile] AS TABLE(
	[NumCols] [int] IDENTITY(1,1) NOT NULL,
	[strRow] [varchar](500) NOT NULL,
	PRIMARY KEY CLUSTERED 
&quot;

Since I&#039;m getting this error in Management Studio, I know it won&#039;t work in VS 2008 either.  However, I did try this in VS 2008 and I am still getting same exception.  So what exactly should I change?</description>
		<content:encoded><![CDATA[<p>Thanks Aneef,</p>
<p>But is there any way to have identity column autoincrement without me changing IDENTITY_INSERT?  Otherwise, how do i get the IDENTITY_INSERT value to remain on?<br />
I tried setting the IDENTITY_INSERT to ON from SQL Management Studio:<br />
&#8221;<br />
SET IDENTITY_INSERT ParentTable ON<br />
GO<br />
DECLARE @InputFile parseInputFile<br />
INSERT INTO @InputFile(NumCols, strRow) VALUES (1, &#8216;A3|BB|C|DDD&#8217;)<br />
select * from @InputFile<br />
&#8221;<br />
But then compiler returned following error:</p>
<p>&#8221;<br />
Msg 1077, Level 16, State 1, Line 2<br />
INSERT into an identity column not allowed on table variables.<br />
&#8221;</p>
<p>And this is using same table UDT, parseInputFile, which is defined as:<br />
&#8221;<br />
CREATE TYPE [dbo].[parseInputFile] AS TABLE(<br />
	[NumCols] [int] IDENTITY(1,1) NOT NULL,<br />
	[strRow] [varchar](500) NOT NULL,<br />
	PRIMARY KEY CLUSTERED<br />
&#8221;</p>
<p>Since I&#8217;m getting this error in Management Studio, I know it won&#8217;t work in VS 2008 either.  However, I did try this in VS 2008 and I am still getting same exception.  So what exactly should I change?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aneef Fashir</title>
		<link>http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/comment-page-1/#comment-164</link>
		<dc:creator>Aneef Fashir</dc:creator>
		<pubDate>Tue, 16 Jun 2009 05:11:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/#comment-164</guid>
		<description>&lt;blockquote&gt;Hi Ryan,

If you supply a value for an identity column in a table-valued parameter, you must issue the SET IDENTITY_INSERT statement for the session.

Hope it Helps&lt;/blockquote&gt;</description>
		<content:encoded><![CDATA[<blockquote><p>Hi Ryan,</p>
<p>If you supply a value for an identity column in a table-valued parameter, you must issue the SET IDENTITY_INSERT statement for the session.</p>
<p>Hope it Helps</p></blockquote>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Daulton</title>
		<link>http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/comment-page-1/#comment-163</link>
		<dc:creator>Ryan Daulton</dc:creator>
		<pubDate>Tue, 16 Jun 2009 02:09:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/#comment-163</guid>
		<description>Hi Aneef,

I like your example very much!  I&#039;ve been looking for a Table UDT example for a long time.  I tried your solution, however, the difference with my code is that my table type has the first column as an Identity column.  
So when I try to execute the InsertFileDetails SP, C# VS 2008 debug says &quot;Insert into IDENTITY column isn&#039;t allowed on table variables.&quot;  How do I fix this?  Here is a snippet of my code:
&quot;
 DataTable dt = new DataTable();
            String[] header = myStringArray[0].Split(&#039;&#124;&#039;);

            DataRow dr = dt.NewRow();
            DataColumn dc = new DataColumn();
            dc.DataType = typeof(Int32);
            dc.ColumnName = &quot;NumCols&quot;;
            
            dt.Columns.Add(dc);
            DataColumn dc2 = new DataColumn();
            dc2.DataType = typeof(string);
            dc2.ColumnName = &quot;strRow&quot;;
            
            dt.Columns.Add(dc2);
            dt.Rows.Add(myStringArray[1]);
&quot;

But the exception doesn&#039;t get caught until I exec the ExecuteNonQuery function.

Thanks!</description>
		<content:encoded><![CDATA[<p>Hi Aneef,</p>
<p>I like your example very much!  I&#8217;ve been looking for a Table UDT example for a long time.  I tried your solution, however, the difference with my code is that my table type has the first column as an Identity column.<br />
So when I try to execute the InsertFileDetails SP, C# VS 2008 debug says &#8220;Insert into IDENTITY column isn&#8217;t allowed on table variables.&#8221;  How do I fix this?  Here is a snippet of my code:<br />
&#8221;<br />
 DataTable dt = new DataTable();<br />
            String[] header = myStringArray[0].Split(&#8216;|&#8217;);</p>
<p>            DataRow dr = dt.NewRow();<br />
            DataColumn dc = new DataColumn();<br />
            dc.DataType = typeof(Int32);<br />
            dc.ColumnName = &#8220;NumCols&#8221;;</p>
<p>            dt.Columns.Add(dc);<br />
            DataColumn dc2 = new DataColumn();<br />
            dc2.DataType = typeof(string);<br />
            dc2.ColumnName = &#8220;strRow&#8221;;</p>
<p>            dt.Columns.Add(dc2);<br />
            dt.Rows.Add(myStringArray[1]);<br />
&#8221;</p>
<p>But the exception doesn&#8217;t get caught until I exec the ExecuteNonQuery function.</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: borith</title>
		<link>http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/comment-page-1/#comment-99</link>
		<dc:creator>borith</dc:creator>
		<pubDate>Thu, 05 Feb 2009 10:08:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/#comment-99</guid>
		<description>cool, i am looking for this for weeks. i&#039;ll try this.
thanks</description>
		<content:encoded><![CDATA[<p>cool, i am looking for this for weeks. i&#8217;ll try this.<br />
thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mb</title>
		<link>http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/comment-page-1/#comment-49</link>
		<dc:creator>mb</dc:creator>
		<pubDate>Fri, 11 Jul 2008 14:03:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/#comment-49</guid>
		<description>FINALLY!!!!  A real sample!!!  All other examples always leave out the client code part of the equation.

This is awesome, your example got me started - the key being the need to convert entities into the datatable... I assume your preparedatatable() function simply creates the datatable with the same types as your UDT.

Now what we need next is the ability to generate the design time database from the UDT automatically to have it typed beforehand.. but we can worry about that later, I&#039;m just thrilled now to have this working... no more XML parsing! yeeehaaa!!!</description>
		<content:encoded><![CDATA[<p>FINALLY!!!!  A real sample!!!  All other examples always leave out the client code part of the equation.</p>
<p>This is awesome, your example got me started &#8211; the key being the need to convert entities into the datatable&#8230; I assume your preparedatatable() function simply creates the datatable with the same types as your UDT.</p>
<p>Now what we need next is the ability to generate the design time database from the UDT automatically to have it typed beforehand.. but we can worry about that later, I&#8217;m just thrilled now to have this working&#8230; no more XML parsing! yeeehaaa!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aneef Fashir</title>
		<link>http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/comment-page-1/#comment-32</link>
		<dc:creator>Aneef Fashir</dc:creator>
		<pubDate>Thu, 27 Mar 2008 04:35:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/#comment-32</guid>
		<description>&lt;strong&gt;Hi Carl, did u check your database columns, and their types, and see whether they match with the columns and types of the datatable.

And are you sure you are using SQL Server 2008 November CTP or later. because passing datatables is not supported prior versions.
&lt;/strong&gt;


</description>
		<content:encoded><![CDATA[<p><strong>Hi Carl, did u check your database columns, and their types, and see whether they match with the columns and types of the datatable.</p>
<p>And are you sure you are using SQL Server 2008 November CTP or later. because passing datatables is not supported prior versions.<br />
</strong></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/comment-page-1/#comment-31</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Wed, 26 Mar 2008 20:25:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/#comment-31</guid>
		<description>Its just what i am trying to do but im using vb and i keep getting a error saying there is no mapping between the datatable and the database ???

i&#039;ve downloaded your code and your doing nothing different than me, So any ideas ???

Many Thanks 
Carl</description>
		<content:encoded><![CDATA[<p>Its just what i am trying to do but im using vb and i keep getting a error saying there is no mapping between the datatable and the database ???</p>
<p>i&#8217;ve downloaded your code and your doing nothing different than me, So any ideas ???</p>
<p>Many Thanks<br />
Carl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mike</title>
		<link>http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/comment-page-1/#comment-3</link>
		<dc:creator>mike</dc:creator>
		<pubDate>Mon, 24 Dec 2007 04:31:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.aneef.net/2007/12/23/sql-server-2008-table-valued-parameters/#comment-3</guid>
		<description>thats interesting</description>
		<content:encoded><![CDATA[<p>thats interesting</p>
]]></content:encoded>
	</item>
</channel>
</rss>
