.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Code Snippets >> Collections >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

DataView to DataTable in C#

Posted By:Pankaj Mishra       Posted Date: August 07, 2008    Points: 10    Category: Collections    URL: http://www.dotnetspark.com  


Below code shows how to convert Dataview to a DataTable in C#. All you have to use ToTable() Method of DataView objects.

Lets See an Example.

C# Sample

public static DataTable GetFilterData(DataTable table)


DataTable dataTable = table;

if (returnDataTable != null)


DataView dataView = new DataView(returnDataTable);

dataView.RowFilter = filterCondition; //some condition

dataTable = dataView.ToTable();


return dataTable;


VB.Net Example

Public Shared Function GetFilterData(ByVal table As DataTable) As DataTable

Dim dataTable As DataTable = table

Dim filterCondition As String = "Col1 == a" 'Your Filter Condition

If dataTable IsNot Nothing Then

Dim dataView As New DataView(dataTable)

dataView.RowFilter = filterCondition

dataTable = dataView.ToTable()

End If

Return dataTable

End Function

Hope this will help you



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend