Dataview column values

  • Thread starter Thread starter JD
  • Start date Start date
J

JD

I need to obtain an mean value of Width column in a Dataview. I can walk
through the Dataview (see below).

How do I extract the values from Width column in the Dataview so they can be
added together?

Would it be better to use a datatable? If so same question.

Dim dt As DataTable = ds.Tables("tblWidths")

Dim dvWidths As New DataView(dt)

dvWidths.RowFilter = "FishSurveyID = " + Me.FishSurveyIDWidths.Text + ""

Dim x As Integer = 0

For Each drv2 As System.Data.DataRowView In dvWidths

x += 1

Next
 
Just off the top I think you can just use the column indexer:

myval += drv2(columnname)

Ian
 
Ian,

I tried this statement
myval += drv2("columnname") or myval += drv2(columnname)
and it did not like it. Anyother suggestions?

jd
 
I just stumbled onto this while looking for something else... it may help you.

http://www.knowdotnet.com/articles/expressions-printable.html

Quote from above web page:

Dim x As Integer = CType(Ds1.Tables("LeaveTable").Compute("SUM(TotalLeaveUsed)",
"EmployeeID = " & lstEmployees.SelectedValue.ToString), Integer)
tbLeaveUsed.Text = x.ToString

So what we did was call the Compute method of the DataTable (which was LeaveTable in our
example). To use it, you just call the aggregate function (SUM, COUNT, AVG etc) and a
Filter expression. So essentially the above statement would read "Give me the Sum of all
of the TotalLeaveUsed Values in LeaveTable (where LeaveTable is a DataTable in Dataset
Ds1) where the EmployeeID Field equals the employee number we got from the Listbox".
 
Back
Top