471,337 Members | 939 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Trying to extract Data from a DataTable

My DataTabel has the following columns: org_id, org_name, parent_id

DataTable dt = dsMyData.Tables["organization"];

This next statement should create a data view with filter that results in
one row

DataView dv = new DataView(dt,"parent_id
= -1","org_id",System.Data.DataViewRowState.CurrentRo ws);

I am trying to add the values from the org_id column to a TreeNode. Tag
field and the org_name column to the TreeNode.Text field. At least I think
that is what I want to do.

I want the org_name fields to be the visible part of the treeView and the
org_id fields to be the values that may be passed to other controls when a
node is selected.

My problem is that I can't figure out how to get at the values in DataTable
Columns.

Here is a sample I found regarding a DataRowView , but DataRowView is not a
member of the DataView...? I see other discussion that talk about an Item
member of a DataView, but my intellisense doesn't inidcate any such member
of a DataView.

The DataRowView sample seems in appropriate because I only have one row, or
at least should have.

[C#]
DataView catView = new DataView(catDS.Tables["Categories"]);

Console.WriteLine("Current Values:");

WriteView(catView);

Console.WriteLine("Original Values:");

catView.RowStateFilter = DataViewRowState.ModifiedOriginal;

WriteView(catView);

public static void WriteView(DataView myView)
{
foreach (DataRowView myDRV in myView)
{
for (int i = 0; i < myView.Table.Columns.Count; i++)
Console.Write(myDRV[i] + "\t");
Console.WriteLine();
}
}
TreeNode tn = new TreeNode();

What do I use to populate these fields?

tn.Text = dv.???

tn.tag = dv.???
Dec 1 '05 #1
0 1562

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Brian Hanson | last post: by
1 post views Thread by Beginner | last post: by
6 posts views Thread by Tejpal Garhwal | last post: by
reply views Thread by Henry | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.