DataTable Processing

F

Fred Nelson

Hi:

I have built and loaded a datatable with three columns and defined the
first as a primary key as below:

' define datatable
dim fvtable as new DataTable
dim fvrow as DataRow
fvtable.Columns.Add("fvident", GetType(String))
+ two more columns

' define primary key
DIM PrimaryKeyColumns(0) as DataColumn
PrimaryKeyColums(0) = fvtable.columns("fvident")
fvtable.PrimaryKey = PrimaryKeyColumns

In this application I'm not looking to databind or set relations to
other tables - I need to create a cycle that will access data in several
locations and allow me to generate form letters - so I must process this
myself.

So: Now that I have it in a DataTable I can't figure out how to:

1) Go to the top and process sequentially in the order of the primary
key: (logically)

datatable.gototop
while datatable.read
// actions
end while

2) perfrom a direct lookup:

dim soughtkey as string = "ABC"

datable.read.keyvalue = soughtkey
if found
// process found
else
// process not found
endif

I've looked all over MSDN and the web and can't find any examples of how
to do this so any and all help would be GREATLY appreciated!

Thanks,

Fred
 
L

Lucas Tam

1) Go to the top and process sequentially in the order of the primary
key: (logically)

datatable.gototop
while datatable.read
// actions
end while

Use the DataTable.Select method to return an array of DataRows. Then you
can loop through the array.

OR

Apply a DataView to the Datatable, ordering by the PK. Loop through the
PK.


2) perfrom a direct lookup:

dim soughtkey as string = "ABC"

datable.read.keyvalue = soughtkey
if found
// process found
else
// process not found
endif

I've looked all over MSDN and the web and can't find any examples of
how
to do this so any and all help would be GREATLY appreciated!

Use the .Find method, or .Select or a Dataview.

Are you sure you looked all over MSDN? ; )
 
F

Fred Nelson

Lucas:

Thanks VERY much for your help with this - I now have the info I need to
move forward.

It must be there somewhere - I spent two hours last night looking at
examples and writing code that didn't work. After another two hours
this morning I made the post. I know that I'm a "newby" so that's
part/most of it - also the examples I found sooner or later ended up
talking about binding, XML, or other things above and beyond what I
needed.

I've noticed that very often there aren't good examples of simple
things. I have a bunch of books that seem to skip over the elementary
steps and immediately teach "binding to XML remote procedure calls that
access stored procedures after generating the meta data to implement a
concurrent backup"!

Sorry for that - I'm tired!!!

Anyhow: Thanks very much for your help!

Fred
 
L

Lucas Tam

It must be there somewhere - I spent two hours last night looking at
examples and writing code that didn't work. After another two hours
this morning I made the post. I know that I'm a "newby" so that's
part/most of it - also the examples I found sooner or later ended up
talking about binding, XML, or other things above and beyond what I
needed.

Ya, I know what you mean about MSDN, sometimes documentation is buried
under a lot of layers.

I often find looking at the members of the class (properties, events,
methods) to be very helpful... sometimes looking over the entire class
gives you more leads.

If all else fails, there's always google and this group : )

Good luck with your program!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top