How to fetch data rows from a data view in C#

Data View is a representation of data table which can be used to access rows in a table. In Database programming sometimes we need to search and extract/copy rows which meet some criteria/condition. C# and .Net framework allows you to do this using rich set of objects available in Visual Studio.

In our example we have a table Groups which is used to store various accounting groups. I want to extract those groups with pgid[Primary Group ID] as 0, this is made possible with Data View object’s FindRows method.

Common.GroupTableView.Sort = "pgid";
 dv.Sort = "pgid";
 DataRowView[] nodes = Common.GroupTableView.FindRows(0);

FindRows () return a collection of data rows, so that we used array of dataRowView to store the objects.

You can use Foreach loop to get access values as follows [ add a tree view control to your C# Project]

foreach (DataRowView node in nodes)

Published by


A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

3 thoughts on “How to fetch data rows from a data view in C#”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.