By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,239 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,239 IT Pros & Developers. It's quick & easy.

DataTable Processing

P: n/a
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

Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Fred Nelson <fr**@smartybird.com> wrote in
news:OP*************@TK2MSFTNGP10.phx.gbl:
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? ; )

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 20 '05 #2

P: n/a
Lucas Tam <RE********@rogers.com> wrote in
news:Xn***************************@140.99.99.130:
Use the .Find method


BTW, the find method is under datatable.rows.find. Find will only search
against the PK.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 20 '05 #3

P: n/a
Lucas:

Thanks VERY much for your help with this - I now have the info I need to
move forward.
Are you sure you looked all over MSDN? ; )

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
Lucas Tam wrote:
Fred Nelson <fr**@smartybird.com> wrote in
news:OP*************@TK2MSFTNGP10.phx.gbl:

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? ; )

Nov 20 '05 #4

P: n/a
Fred Nelson <fr**@smartybird.com> wrote in news:#YVUZBmdEHA.2520
@TK2MSFTNGP12.phx.gbl:
Are you sure you looked all over MSDN? ; )


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!

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.