0

Case 1

 DataSet oDsParent = new DataSet();
     DataTable odt = new DataTable();

     odt.Columns.Add(new DataColumn("DOC_GENO_KEY", typeof(int)));
     odt.Columns.Add(new DataColumn("RESOURCE_TYPE", typeof(string)));
     odt.Columns.Add(new DataColumn("ROUTING_SUB_ID", typeof(int)));

     odt.Rows.Add(2, "TEST1", 2);
     odt.Rows.Add(4, "ADMIN", 2);
     odt.Rows.Add(7, "TEST2", 2);

     oDsParent.Tables.Add(odt);
     oDsParent.AcceptChanges();

    string sTemp =new string ();
     sTemp = "(DOC_GENO_KEY = 4 OR DOC_GENO_KEY = 2) AND (RESOURCE_TYPE = 'TEST1' OR DOC_GENO_KEY = 2 OR ROUTING_SUB_ID = 2)";

Case 2

 oDsParent = new DataSet();
     odt = new DataTable();
     odt.Columns.Add(new DataColumn("DOCUMENT_ATTACHED", typeof(string)));
     odt.Columns.Add(new DataColumn("ATTACHMENT TYPE", typeof(int)));

     odt.Rows.Add("DOC1", 2);
     odt.Rows.Add("DOC2", 1);
     odt.Rows.Add("DOC3", 0);

     oDsParent.Tables.Add(odt);
     oDsParent.AcceptChanges();

    sTemp = "(DOCUMENT_ATTACHED = 2 OR DOCUMENT_ATTACHED = 1 )";

The dataset oDsParent is formed dynamically In Case 1 there are 3 columns and their respective data & in Case 2 there are 2 columns with the data. These columns are filled based on condition in the same dataset(oDsParent) dynamically so that the columns formed are different at each time. I need to Query the dataset based on the string( sTemp) below which also changes according to the data tables based on the condition. I cannot use Field("Column name") in the query as there are no fixed columns and they change dynamically. i need a LINQ that can be used generally to filter the dataset no matter which columns are created according to their respective string. I have created a demo of the dataset & string to understand my issue better.

shiju87
  • 112
  • 2
  • 11
  • You could use the classic approach [`DataTable.Select("(DOC_GENO_KEY = 4 OR DOC_GENO_KEY = 2)")`](http://msdn.microsoft.com/en-us/library/det4aw50.aspx) – Tim Schmelter Nov 22 '12 at 11:48
  • The Filter condition based on DOC_GENO_KEY is so lengthy in the Real scenarion that the IIS is crashing while I use DataTable.Select() and also there are more than 1000 rows in the Dataset oDsParent. I need a replacement for this case. – shiju87 Nov 22 '12 at 12:15
  • Why do you need to use this dynamic filter at all? Isn't it possible to filter by static columns(f.e. by `Linq-To-DataSet`) or - even more efficient - filter in the database directly? – Tim Schmelter Nov 22 '12 at 12:17
  • The columns keep on changing based on different modules, but the dataset that is used is the same in every case. I cant use where in linq because I cant say which columns are loaded in the dataset at that time. so I have to filter the dataset based on the query at the specefic time to display the changed dataa. – shiju87 Nov 22 '12 at 12:25

0 Answers0