Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have multiple data table in dataset example five data tables in dataset.now i want to split particular data table.how to do it.

What I have tried:

I have tried split data table using name.
Posted
Comments
Suvendu Shekhar Giri 24-Oct-16 7:06am    
.. and after splitting what will do with it?
How about Google search?
Raja Ganapathy 24-Oct-16 7:12am    
after splitting dataset have another data table.Means i have five data table after splitting data set must have only 4 data table.

If you want to separate the table from dataset, then take a new datatable and assign it something like this dt = ds.Tables[n].

If you want some records from a particular table, the create a new datatable and add new rows from the dataset's table.
 
Share this answer
 
Here is some thing I do in my project. In the below example I am getting dataset from different tables User and Roles. One my stored procedure is executed and I have my dataset I am using
ds.Tables[0].AsEnumerable()

- to get the data from data table in to userinfo. Further I am using
ds.Tables[1].AsEnumerable()
to get access to the second table in the dataset. You can try to do in your case as well.
SQL
DataSet ds = dm.ExecuteQuery("SpGetUserDetails", parameters);
 User userInfo = (from r in ds.Tables[0].AsEnumerable()
                 select new User
                 {
                     FullName = r["FirstName"].ToString() + " " + r["LastName"].ToString(),
                     FirstName = r["FirstName"].ToString(),
                     MiddleName = r["MiddleName"].ToString(),
                     LastName = r["LastName"].ToString(),
                     EmailId = r["EmailId"].ToString()
                  }).SingleOrDefault();

userInfo.Roles =(from r in ds.Tables[1].AsEnumerable()
                 select new UserRoles
                 {
                     UserRoleMappingId = Convert.ToInt32(r["UserRoleMappingId"].ToString()),
                     UserRoleId = Convert.ToInt32(r["UserRoleId"].ToString()),
                     UserId = Convert.ToInt32(r["UserId"].ToString()),
                      RoleName = r["RoleDescription"].ToString()
                }).ToList();


Hope this helps.

Happy Learning
 
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