Solved

efficient way to insert table in dataset into database?

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

627 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