0

I want to query a database and with the results, i want to process them. While im processing them, some of them will need to be inserted into another database. Since i cannot run another query with an open SqlDataReader (that i know of). I was thinking about putting the data from the SqlDataReader into a DataTable while i process it. Is there a built in way to do this or is there another solution that can accomplish the same idea?

3
  • 1
    Check this link: msdn.microsoft.com/en-us/library/cfa084cz(v=vs.80).aspx Commented Mar 2, 2012 at 14:16
  • If its SqlServer have you thought of using SSIS, using DataTables and DataSets for manipulating stored data is a somewhat convoluted process compared to what can be achieved with SSIS. msdn.microsoft.com/en-us/library/ms141026.aspx Commented Mar 2, 2012 at 14:22
  • @Lloyd I dont have that kind of access to the DB to setup SSIS, i only have a read only Sql id. Thanks for the idea though. Commented Mar 2, 2012 at 14:27

2 Answers 2

1
SqlDataReader reader = com.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);

With the rest of the standard set-up and tear-down of SqlCommand objects, of course.

Sign up to request clarification or add additional context in comments.

Comments

1

The easiest way would be to use a DataAdapter to fill a datatable. Then process the data and update the database. Filling a dataset does not tie up the connection once the fill is complete.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.