Solved

efficient way to insert table in dataset into database?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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 video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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

19 Experts available now in Live!

Get 1:1 Help Now