CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2008
    Posts
    7

    Best way to write DataSet to database table

    Referring to my previous thread i would be interested to know your opinion about what's the best, most efficient approach for writing a method that would accept three parameters:

    1) database connection
    2) DataSet
    3) name of a table in database

    and write the content of the DataSet's Table[0] to an empty, structurally identical database table?

    The passed DataSet-parameter would be filled with loads of data. With the method i have described in my previous post, using DataAdapter.Update, it takes about 1 minute to insert 10 000 rows and that's just way too slow.
    Last edited by cokelite; May 14th, 2008 at 02:20 PM.

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Best way to write DataSet to database table

    If you are doing more than about 50 rows at a time, AND if you are using SQL Server 2005 or later (this may or may not apply to other DMBS engines).....

    1) Write the Rows to an XML Stream
    2) Send the Entire Stream to the Database as a Sotred Proc PArameter
    3) Convert the XML into a Table VARIABLE
    4) Intert the TableVariable into the Real Table.


    btw: 0.006 Seconds per row is actually quite good....

    I am very curoius as to what type of application would be posting data of this nature (I have worked on systems with well over 10M transactions per hr, and usually find that the pattern you describe is the result of some poor architectural decisions....

    Even the idea that you want to pass a connection around raises concerns.....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Aug 2005
    Location
    Seattle, Wa
    Posts
    179

    Re: Best way to write DataSet to database table

    Regardless of your reasons, or whether or not you "should" be doing things as you are, there is a faster method for bulk importing of massive amounts of data.

    SqlBulkCopy Class in System.Data.SqlClient namespace is something you should look into.

  4. #4
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Best way to write DataSet to database table

    Youve gotten something in your data access code or database design, wrong I think.. Last time I used a TableAdapter to Update() a dataset with 100,000 rows, it inserted 800rows/second (and a trigger executes somewhere in the region of 25 string replacements/case manipulations per row)

    Actually, the string replacements dont seem to knock the performance much, because using Oracle's client instead of the microsoft one, and employing a transfer array of 500 rows buffer saw the rate rise to over 3000 rows/sec..

    You can check to see if the adapter is performing a select immediately after the insert, to check for values caluclated by the database.. I dont know where to find such an option on a DA, as I work nearly exclusively with tableadapters and its a tickbox in the TA wizard. Perhaps someone else will know
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  5. #5
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Best way to write DataSet to database table

    Quote Originally Posted by cjard
    Youve gotten something in your data access code or database design, wrong I think.. Last time I used a TableAdapter to Update() a dataset with 100,000 rows, it inserted 800rows/second (and a trigger executes somewhere in the region of 25 string replacements/case manipulations per row),
    Thas 1.25 mS per row. This is well within the range of variance that could be caused by the machine (CPU, Memory, etc), data file (fragmentation, etc) or other normal variances....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured