Reputation: 1970
I am trying to get a value out of an array by name. The purpose of this is to send these parameters to both SSRS and to a transactional query.
I have an XML type ParameterValue:
'report paramerters
Dim parametersTransactional(3) As ParameterValue
parametersTransactional(0) = New ParameterValue()
parametersTransactional(0).Name = "StartDate"
parametersTransactional(0).Value = "2012-01-01T00:00:00"
parametersTransactional(1) = New ParameterValue()
parametersTransactional(1).Name = "EndDate"
parametersTransactional(1).Value = "2012-06-01T00:00:00"
parametersTransactional(2) = New ParameterValue()
parametersTransactional(2).Name = CustomersCustomerLocation"
parametersTransactional(2).Value = "1, 2, 3, 4, 5"
I thought I could get the index of a name then get the value like this;
Dim startDate As String = "StartDate"
Dim idxStartDate As Integer = Array.IndexOf(parameters, startDate)
Or like this:
Dim start2 As Integer = parameters.FindIndex(startDate)
ParameterValue is of type:
'''<remarks/>
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.17929"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices")> _
Partial Public Class ParameterValue
Inherits ParameterValueOrFieldReference
Private nameField As String
Private valueField As String
Private labelField As String
'''<remarks/>
Public Property Name() As String
Get
Return Me.nameField
End Get
Set
Me.nameField = value
End Set
End Property
'''<remarks/>
Public Property Value() As String
Get
Return Me.valueField
End Get
Set
Me.valueField = value
End Set
End Property
'''<remarks/>
Public Property Label() As String
Get
Return Me.labelField
End Get
Set
Me.labelField = value
End Set
End Property
End Class
So I'm missing some crucial step.
Upvotes: 0
Views: 223
Reputation: 43743
You can accomplish that easily using the First
or FirstOrDefault
method. They are both LINQ extension methods. For instance:
Dim p As ParameterValue = parameters.FirstOrDefault(function(x) x.Name = "StartDate")
Upvotes: 2
Reputation: 6948
You second attempt was getting close. something like this will work:
Dim startdate As DateTime = DateTime.Parse(parametersTransactional(Array.FindIndex(parametersTransactional, Function(x) x.Name = "StartDate")).Value)
Upvotes: 1