Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I have below code, where in I am creating a dataset based on a query to Oracle mdb.
C#
....
      OracleDataAdapter adapter = new OracleDataAdapter(sqlstr, conn);
       OracleCommandBuilder builder = new OracleCommandBuilder(adapter);
       DataSet dataset = new DataSet();
       adapter.Fill(dataset);

       DataTable dataTable = dataset.Tables[0];
....

I would like to have the highlighted code in a loop, and then add the dataset objects to a common datatable outside the loop.

How can this be implemented?

Thanks
Posted
Updated 1-May-14 23:51pm
v2
Comments
[no name] 5-May-14 6:17am    
http://msdn.microsoft.com/en-us/library/aeskbwf7(v=vs.110).aspx
[no name] 5-May-14 6:17am    
http://www.codeproject.com/Questions/168959/Adding-Datatable-to-an-existing-Dataset

well you can simply add the datatables to dataset by usign below method

C#
ds.tables.add(dt);

add some for loop if you want to add multiple datatables to your dataset.
 
Share this answer
 
Comments
agent_kruger 30-May-14 10:09am    
+5 sir, simple solution (not my question).
DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        ds.Merge(dt);
 
Share this answer
 
Ok to add datatables to a dataset you first need to declare you dataset outside your loop. Otherwise you are creating your dateset everytime you loop so you are always only gonna have one value.
So code would look like

DataSet dsCompleteDataSet = new DataSet();

//Loop
for(int i = 0; i < counter; i++)
{
  OracleDataAdapter adapter = new OracleDataAdapter(sqlstr, conn);
       OracleCommandBuilder builder = new OracleCommandBuilder(adapter);
       DataSet dataset = new DataSet();
       adapter.Fill(dataset);
      dsCompleteDataSet.Tables.Add(dataset.Tables[0]);
}


Hope that helps.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900