Tuesday, May 11, 2010

How to select unique fields in DataSet or DataTable at runtime in C# & Ado.Net

Please refer the following code to filter the unique values from DataSet or DataTable at runtime.


DataTable dt=new DataTable();
DataTable dt = GetProductDetaila(); // Get all the details of product


DataView view = dt.DefaultView; // Create a dataview on the datatable


view.Sort = "ProductId,ProductName"; // Need to sort the records based on the ProductId and ProductName


DataTable newTable = view.ToTable("UniqueProductNames", true, "ProductId", "ProductName", 
"ImageURL"); 


// These are the unique entries in the dataset that are to be filtered. If you need more fields then write them in comma seperated values.

No comments:

Post a Comment