Click here to Skip to main content
15,882,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Dataset with results I get from the DB, I keep that as a base dataset and would like any filtering will be done on the second Dataset.

I ensure I have the filtered data on datatable but when I use dataset.table.add

the dataset is always empty

code below
protected void showMembers(Boolean filtered=false)
          using (var cn = GetConnection())
              string cmsGetProfiles = "SELECT * FROM [Vm_siteMembers] order by [Last Login Time] desc ";

              SqlDataAdapter EventsAdapter = new SqlDataAdapter(cmsGetProfiles, cn);
              BaseMembersListDS.Clear();// this DataSet defined as public static


              using (DataSet filteredMemberListDS = new DataSet())
                  if (filtered)
                      DataTable dt = new DataTable(); dt.TableName = "filtered";

                      foreach (var item in BaseMembersListDS.Tables[0].Columns)

                      foreach (DataRow dr in BaseMembersListDS.Tables[0].AsEnumerable().Take(5))

                  MembersdataBind(filteredMemberListDS);//why filteredMemberListDS is empty

      protected void MembersdataBind(DataSet filteredMemberList)

          MemebersDdl.DataSource = filteredMemberList;

What I have tried:

Columns headers on datatable match by doing this

foreach (var item in BaseMembersListDS.Tables[0].Columns)
Richard MacCutchan 9-Dec-23 10:28am    
The issue is most likely with the data being returned, so you need to use the debugger to examine what is being read from the database at each point.
Member 4529316 9-Dec-23 10:48am    
no issues when debugging, datatable has data and it add nothing
Richard MacCutchan 9-Dec-23 11:08am    
Sorry, no one here can guess what is going on, or what you mean by that statement. You need to gather some proper details about what is happening and add them to your question.

1 solution

DEBUGGER! Ruin the code under the debugger and set a breakpoint on the line that fills the DataSet. Execture the code one line at a time and hover the mouse over variables to see their content. You could have figured this out in seconds!

The problem you are looking at is obvious. You .Merge a table you got into a new DataSet, filteredMemberListDS, then you called filteredMemberListDS.Clear() on it, which killed all the tables in the DataSet, and you're wondering why you get no data back from it? YOU KILLED THE TABLES IN THE DATASET!
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