2011-09-05 53 views
0

我有一个具有2个固定列和动态行的2-d数组列表。 arraylist将被分配到下面的代码末尾的会话变量。我的问题是如何从会话中循环播放列表来获得它的价值?在会话中从二维数组列表中获取值

If .SQLDS.Tables(.sSQLDSTbl).Rows.Count > 0 Then 
    Dim NoOfAdjType(1, .SQLDS.Tables(.sSQLDSTbl).Rows.Count - 1) 

    For iRow As Integer = 0 To .SQLDS.Tables(.sSQLDSTbl).Rows.Count - 1 
     If Not .SQLDS.Tables(.sSQLDSTbl).Rows(iRow).Item("i_commAmt") Is System.DBNull.Value Then 
      NoOfAdjType(0, iRow) = .SQLDS.Tables(.sSQLDSTbl).Rows(iRow).Item("productType") 
      NoOfAdjType(1, iRow) = Format(.SQLDS.Tables(.sSQLDSTbl).Rows(iRow).Item("i_commAmt"), "#,##0.00") 
     End If 
    Next 

     Session("iNoOfAdjAmtType") = NoOfAdjType 
End If 

我都试过,但它给我的错误“太多的参数‘公共可覆盖默认属性项目(指数为整数)作为对象’

Dim NoOfAdjType As ArrayList = CType(Session("iNoOfAdjAmtType"), ArrayList) 
For i As Integer = 0 To NoOfAdjType.Count 
    Dim a As String = NoOfAdjType(0, i) 
    Dim b As String = NoOfAdjType(1, i) 
Next 

回答

0

您正在处理的类型是Object(,)。因此,从会话中读取时,您可以将其重新转换为此类型。

下面是一个article on MSDN这说明了如何读取会话值:

Dim NoOfAdjType as Object(,) = CType(Session("iNoOfAdjAmtType"), Object(,)) 
' do something with the list 

如果你想执行检查安全保证,有一个项目在会议定id:

If Session.Item("iNoOfAdjAmtType") IsNot Nothing Then 
    ' We have a value in the session with the given id 
    Dim NoOfAdjType as Object(,) = CType(Session("iNoOfAdjAmtType"), Object(,)) 
End If 
+0

感谢,但我怎样才能在行数数组列表? –

+0

@Danferd,'NoOfAdjType.GetLength(0)'和'NoOfAdjType.GetLength(1)'。 –

+0

谢谢@Darin ... –

0

我不确定什么是数组的数据类型,但是这是如何操纵VB.NET中的多维数组,假设数据类型为对象

' declaring variable of multi-dim array 
Dim NoOfAdjType As Object(,) 
' create array object of needed dimension (you may use redim keyword) 
NoOfAdjType = new Object(1, .SQLDS.Tables(.sSQLDSTbl).Rows.Count - 1) {} 

... 

' push it in session 
Session("iNoOfAdjAmtType") = NoOfAdjType 

... 

' get back from session 
NoOfAdjType = DirectCast(Session("iNoOfAdjAmtType"), Object(,)) 
... 
For i As Integer = 0 To NoOfAdjType.GetLength(0) 
    For j As Integer = 0 To NoOfAdjType.GetLength(1) 
     Dim a As Object = NoOfAdjType(i, j); 
     ... 
    Next 
Next 

见阵列MSDN文章中VB.NET:http://msdn.microsoft.com/en-us/library/wak0wfyt.aspx

0

试试这个,

Dim a As String = NoOfAdjType(0)(0,0) 

或者使用

For Each arr As Object(,) In NoOfAdjType 

Next