Passing a Datavie to a Subroutine

G

Guest

I want to pass a dataview to another subroutine. I've successfully created
the datavew as follows:

For Each CriteriaDetailRow In AlertData.AlertDS.Tables("EventCriteria").Rows

Dim foundRows() As DataRowView = Min_NumView.FindRows(New
Object() {CriteriaDetailRow.Item("Min_Num")})

For Each MinGPSHistoryDetailRow In foundRows

I now want to pass "foundRows" to a subroutine for futher processing as
follows:

NoActivity(foundRows)

The foundRows collection has rows and columns that I need to access. I
defined the function call as follows:

Function NoActivity(InputData)

I'm receiving the collection as follows:

dim GoodData as Array = InputData
I realize that I need to use "For each in GoodData" to read thru the array.

But how do I access the columns of data that I also need? The collection is
results of a datatable.
Thanks
 
J

Jay B. Harlow [MVP - Outlook]

Larry,
But how do I access the columns of data that I also need? The collection
is
results of a datatable.
Do you want to know what columns are available (DataTable.Columns
collection) or do you want to know you to get the value of a specific
column?

If you want to know what columns are available (DataTable.Columns
collection):

You have two options. Explicitly pass the DataTable that the rows are coming
from.

NoActivity(foundRows, Min_NumView.Table)

Or implicitly retrieve the DataTable from the rows passed.
Function NoActivity(InputData() As DataRowView)
Dim table As DataTable = InputData(0).Row.Table
- or -
Dim table As DataTable = InputData(0).DataView.Table

Once you have the DataTable, you can use its Columns collection to get what
columns are available.

I would recommend you avoid using Array directly instead defining the array
for the type it really is:

dim GoodData() as DataRowView = InputData

Or better yet, simple define the InputData parameter as an array of
DataRowView:
Function NoActivity(InputData() as DataRowView)

I would also recommend that you put "Option Strict On" at the top of each of
your source files, as this will identify some errors at compile time, rather
then leaving them for hard to find errors at runtime.

Once you have properly defined variables (DataRowView() instead of Array)
you can simply use

Sub NoActivity(inputData() as DataRowView)
For each row As DataRowView In inputData
dim id As Integer = row("column1")
Next
End Sub

If you don't have it I would strongly recommend you purchase David Sceppa's
"Microsoft ADO.NET" from MS Press is a good Desk Reference for ADO.NET, it
provides a lot of useful information on getting performance out of data
adapters & datasets.

Hope this helps
Jay
 

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