Click here to Skip to main content
15,886,714 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Dear Friends,

I have a dataset in which there are multiple tables for e.g. at index 0,1,2.

I want to filter the table data at index 1, which i am doing and after the method (which returns the filtered datatable) returns the datatable..I want to add it to my existing dataset at index 1 only.

I am not able to do that.

Kindly help.

Thanks

Varun Sareen
Posted
Comments
Sunasara Imdadhusen 15-Mar-11 7:13am    
You can access it by Name!!
Varun Sareen 15-Mar-11 7:39am    
thanks :)

//<summary>
       /// Routine to filter first table and replace exiting table with filtered records.
       // </summary>
       // <param name="sourceSet">Dataset instance to be manipulated</param>\n
      private void _FilterAndInsert(DataSet sourceSet)
       {
           ///Apply your filter clauses in Select() function parameter
           DataRow[] rows = sourceSet.Tables[0].Select("filter clauses here...");
           ///Get the structure of source table
           DataTable tempTable = sourceSet.Tables[0].Clone();
           ///Add the filtered rows in temp table
           foreach (DataRow row in rows)
           {
               tempTable.Rows.Add(row.ItemArray);
           }
           tempTable.AcceptChanges();
           ///Create new dataset
           DataSet resultSet = new DataSet();
           ///Add temp table at first index or modify this code sequence as you require
           resultSet.Tables.Add(tempTable);
           for (int index = 1; index < sourceSet.Tables.Count; index++)
           {
               ///Set the copy of source table in local instance
               DataTable tableToAdd = sourceSet.Tables[index].Copy();
               ///Remove from source to avoid any exceptions
               sourceSet.Tables.RemoveAt(index);
               ///Add the copy to result set
               resultSet.Tables.Add(tableToAdd);
           }
           ///Set the copy to source table from result set
           sourceSet = resultSet.Copy();
       }
 
Share this answer
 
v3
Comments
Varun Sareen 15-Mar-11 7:40am    
thanks avigodse :) you rocks..:)
ADO.NET enables you to create DataTable objects and add them to an existing DataSet. You can set constraint information for a DataTable by using the PrimaryKey and Unique properties.

For more information check this

http://msdn.microsoft.com/en-us/library/aeskbwf7%28v=vs.80%29.aspx[^]
 
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