Solved

efficient way to insert table in dataset into database?

Posted on 2004-10-14
3
157 Views
Last Modified: 2012-08-13
Dear all,

I have a dataset with a table, which was filled by some process. I would like to insert the table into my database. At the moment I am using something like this:

primary_key = performScalarQuery( "select last_insert_id();", connection, transaction );

for( int c = 0; c < dataSet.Tables[ "xx" ].Rows.Count; c++ )
{
x = dataSet.Tables[ "xx" ].Rows[ c ].ItemArray[ 0 ].ToString();
      y = dataSet.Tables[ "xx" ].Rows[ c ].ItemArray[ 0 ].ToString();
                                                
query = "INSERT INTO xx (";
query = query + "x,";
query = query + "y,";
            query = query + "variable_details_uid) values (";

            query = query + " " + x + " , ";
            query = query + " '" + y + "' , ";
            query = query + " " + primary_key + "); ";

      performUpdateQuery( query, connection, transaction );
}

This works fine. I am just wondering whether there is a better way to do this. Any pointers would be very much appreciated. Thanks.

Christian
0
Comment
Question by:csetzkorn
3 Comments
 
LVL 28

Accepted Solution

by:
mmarinov earned 125 total points
ID: 12307180
Hi csetzkorn,
the better way is to fill the dataset by adapter and check for changes in the dataset
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconautomaticallygeneratedcommands.asp

Regards!
B..M
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

17 Experts available now in Live!

Get 1:1 Help Now