Solved

efficient way to insert table in dataset into database?

Posted on 2004-10-14
3
164 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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