Try something like this:
For Each result In results
Dim x As String = result.FundNumber
Next
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am getting data from a SQL server in the form of a data table. I am grouping the data by VendorID and concatenate the row data if there are multiple values of the field. This code is given below and it works fine.
Dim dt As DataTable = GetVendorData()
Dim results = From p In dt.AsEnumerable()
Group p By VendorID = p.Field(Of String)("VenID") Into g = Group
Select New With {
Key .VendorID = VendorID,
Key .FundNumber = String.Join(";", From i In g Select i.Field(Of String)("FundNumber")),
Key .Statefund = String.Join(";", From i In g Select i.Field(Of String)("Statefund")),
Key .State = String.Join(";", From i In g Select i.Field(Of String)("State"))
}
I tried to loop through and get the individual field data as follows
For Each result As DataRow In results
Dim x As String = result.Field(Of String)("FundNumber"))
Next
But I am getting the following error.
System.InvalidCastException
HResult=0x80004002
Message=Unable to cast object of type 'VB$AnonymousType_1`4[System.String,System.String,System.String,System.String]' to type 'System.Data.DataRow'
When I tried "For Each result In results", it doesn't even compile. I am getting this error: ""result" is not declared. It may be inaccessible due to its protection level"
Try something like this:
For Each result In results
Dim x As String = result.FundNumber
Next