<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Passing Datatable to Stored procedure &#8211; Sibeesh Passion</title>
	<atom:link href="https://www.sibeeshpassion.com/tag/passing-datatable-to-stored-procedure/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Wed, 02 Jun 2021 15:17:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>Passing Datatable to Stored procedure &#8211; Sibeesh Passion</title>
	<link>https://www.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Passing a DataTable to a Stored Procedure</title>
		<link>https://www.sibeeshpassion.com/passing-a-datatable-to-a-stored-procedure/</link>
					<comments>https://www.sibeeshpassion.com/passing-a-datatable-to-a-stored-procedure/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sun, 31 May 2015 13:21:13 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Passing Datatable in SQL]]></category>
		<category><![CDATA[Passing Datatable to Stored procedure]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Stored Procedure]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=3001</guid>

					<description><![CDATA[This article explains how we can pass our data table to a stored procedure in C#. We all passed parameters to our stored procedures right? What if we get a situation that to pass a bunch of arguments to a stored procedure, for example a normal data table which we create. This post helps you understand it in a step by step manner. I hope you will like it. Step 1 Create a table: [sql] create table TableTest ( ID INT IDENTITY(1,1) PRIMARY KEY ,NAME VARCHAR(10) ,ADDR VARCHAR(10) ) [/sql] Step 2 Create table types: [sql] CREATE TYPE TABLETEST AS [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This article explains how we can pass our data table to a stored procedure in C#. We all passed parameters to our stored procedures right? What if we get a situation that to pass a bunch of arguments to a stored procedure, for example a normal data table which we create. This post helps you understand it in a step by step manner. I hope you will like it. </p>
<p><strong>Step 1</strong></p>
<p>Create a table:<br />
[sql]<br />
create table TableTest<br />
(<br />
ID INT IDENTITY(1,1) PRIMARY KEY<br />
,NAME VARCHAR(10)<br />
,ADDR VARCHAR(10)<br />
)<br />
[/sql]</p>
<p><strong>Step 2</strong></p>
<p>Create table types:<br />
[sql]<br />
CREATE TYPE TABLETEST AS TABLE<br />
(ID INT)<br />
[/sql]</p>
<p><strong>Step 3</strong></p>
<p>Insert some value:<br />
[sql]<br />
INSERT INTO dbo.TABLETEST VALUES (&#8216;SIBI&#8217;, &#8216;ABCD&#8217;)<br />
INSERT INTO dbo.TABLETEST VALUES (&#8216;SIBEESH&#8217;, &#8216;EFGH&#8217;)<br />
[/sql]</p>
<p><strong>Step 4</strong></p>
<p>Create a procedure with table as parameter:<br />
[sql]<br />
CREATE PROCEDURE SELECTTABLETEST<br />
(<br />
@TABVAR TABLETEST READONLY<br />
)<br />
AS<br />
BEGIN<br />
SELECT * FROM TABLETEST WHERE ID IN (SELECT ID FROM @TABVAR)<br />
END<br />
[/sql]</p>
<p><strong>C# Function</strong><br />
[csharp]<br />
private void passindDataTableToProcedure()<br />
{<br />
   try<br />
   {<br />
      DataTable dt = new DataTable();<br />
      dt.Columns.Add(&quot;ID&quot;);<br />
      var dr = dt.NewRow();<br />
      dr[&quot;ID&quot;] = 1;<br />
      dt.Rows.Add(dr);<br />
      using (SqlConnection cn = new SqlConnection(@&quot;Data Source=SIBEESH\SQLEXPRESS;Initial Catalog=Task;Integrate<br />
      d Security=True&quot;))<br />
      {<br />
         if (cn.State == ConnectionState.Open)<br />
         cn.Close();<br />
         cn.Open();<br />
         using (SqlCommand cmd = new SqlCommand(&quot;SELECTTABLETEST&quot;))<br />
         {<br />
            cmd.CommandType = CommandType.StoredProcedure;<br />
            cmd.Connection = cn;<br />
            cmd.Parameters.AddWithValue(&quot;@TABVAR&quot;, dt);<br />
            using(SqlDataAdapter da=new SqlDataAdapter(cmd))<br />
            {<br />
               da.Fill(dt);<br />
            }<br />
         }<br />
      }<br />
   }<br />
   catch<br />
   {<br />
   }<br />
}<br />
[/csharp]  </p>
<p><strong>Conclusion</strong></p>
<p>What do you think about this? Are you using Spire.PDF yet? Do you plan to try this?Did I miss anything that you may think which is needed?. I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on Stack Overflow instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I am able to.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/passing-a-datatable-to-a-stored-procedure/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
	</channel>
</rss>
