Passing Array or DataSet from C# to Sql Server as parameter

Posted on 2012-09-19
Last Modified: 2012-09-20

I have an application in which I generate either an array or a dataset from answers to a test (usually about 35 in length)

Currently, I make 35 trips to the database with code something like

 string[,] scorray = new string[100, 5];
bool Success = false;
for (int i = 0; i <= scorray.GetUpperBound(0); i++)
Success = AddToDb(scorray[i,0], scorray[i,1];

Open in new window

Is there anyway I could send the array as a dataset to SQL Sever and then use that dataset/table as a parameter which would be inserted into the the table at the SQL server end?

If so, what would the C# code look like, what would the T-SQL look like?  Would it be much faste?

Any help appreciated.

Question by:RBS
    LVL 15

    Expert Comment

    by:Minh Võ Công
    LVL 69

    Accepted Solution

    if you are using SQL 2008 or better, you can use TVP (table value parameter) as shown in

    If you are still using SQL 2005, check

    Author Closing Comment

    Great emoreau - thanks - I have 2008 - excellent article!


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now