Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

efficient way to insert table in dataset into database?

Posted on 2004-10-14
3
Medium Priority
?
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 28

Accepted Solution

by:
mmarinov earned 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

705 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