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

Passing a Datavie to a Subroutine

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


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

"Larry Bird" <La*******@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...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

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.