Build your professional network on facebook via our app Go to app
 
 
Activity:  8 views;  last activity : 07 06 2010 20:18:09 +0000

 
 Refer 25
Share
 
 
  Rate : 
 
 
 
 
  0
 
 
 
 
 
1
1 Passing datatable to store procedure in SQL Server 2008

Passing datatable to store procedure in SQL Server 2008

idea posted by prashant pamani Project Leader -(Technical), Sunbelt Outsourcing Pvt Ltd

Here are good news for .net developer. Now we can pass the datatable directory to Store Procedure in SQL Server 2008

First you have to create type

CREATE TYPE  CategoryTableType AS TABLE
    ( CategoryID int, CategoryName nvarchar(50) )

Now create SP which accept the table value parameter. Here readonly word is required.

CREATE PROCEDURE usp_UpdateCategories
    (@tvpNewCategories dbo.CategoryTableType READONLY)

Now Pass datatable to store procedureusing (connection)
{
// Create a DataTable with the modified rows.
DataTable addedCategories =
  CategoriesDataTable.GetChanges(DataRowState.Added);

// Configure the SqlCommand and SqlParameter.
SqlCommand insertCommand = new SqlCommand(
    "usp_InsertCategories", connection);
insertCommand.CommandType = CommandType.StoredProcedure;
SqlParameter tvpParam = insertCommand.Parameters.AddWithValue(
    "@tvpNewCategories", addedCategories);
tvpParam.SqlDbType = SqlDbType.Structured;

// Execute the command.
insertCommand.ExecuteNonQuery();
}

0
No supporting Arguments for this idea
Add your argument:

Add your Idea
Idea* : 
Add your argument:
edit in rich text ...
Could not find any idea interesting in: "Passing datatable to store procedure in SQL Server 2008" ? Click here to add a new idea...

Found the idea contest "Passing datatable to store procedure in SQL Server 2008"  interesting ?  Click here to refer to your connections and communities
Leading Recruitment Firm
Maximus Talent Resource Management began operations in 2007 as a professional placement services company to cater to the manpower needs in marketing, sales and advertising. In the past year, we have forayed into IT, ITES and ERP sectors, across all levels. We are committed to a result oriented......
Viewers also viewed
Dynamic Management Views   The dynamic management views (DMV’s) in SQL Server 2005 are designed...
 
11 referals 6 comments, 1828 views
Education is nothing but giving knowledge to individuals, some grab it quickly some may take...
 
1897 referals 47 arguments, 2859 views
Yes vs No
 
58 referals 2 arguments, 73 views
more...  
Recent Knowledge (4)
When we are watching news channels or any other channel or reading news papers you bump upon...
 
2022 referals 11 votes, 200 views
we all know the perils of talking on cell phones while driving. besides being hazourdous to...
 
290 referals 2 votes, 36 views
more...  
More From Author
Quality is the Absence of Problems Something doesn’t cause me any problems, and I have no complaints about it, it doesn’t get in the way of work or play, it’s always held up, never breaks, never dies, it’s “Old Reliable” – that’s a sure sign of...
more...