从会话中的二维数组列表中获取值

发布于 2024-12-03 02:37:06 字数 975 浏览 0 评论 0 原文

我有一个二维数组列表,有 2 个固定列和动态行。数组列表将被分配给下面代码末尾的会话变量。我的问题是如何从会话中循环遍历数组列表以获取其值?

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

I have an 2-d arraylist with 2 fixed columns and dynamic rows. The arraylist will be assigned to the session variable at the end of the code below. My question is how can loop thorugh the arraylist from the session to get its value?

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

I have tried this but it's giving me error 'Too many arguments to 'Public Overridable Default Property Item(index As Integer) As Object'

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尘世孤行 2024-12-10 02:37:06

您正在处理的类型是Object(,)。因此,当从会话中读取数据时,您可以将其转换回这种类型。

以下是 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

The type you are dealing with is Object(,). So when reading from the session you can cast it back to this type.

Here's an article on MSDN which illustrates how to read values from session:

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

And if you wanted to perform the check safely ensuring that there is an item with the given id in the session:

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
雨落星ぅ辰 2024-12-10 02:37:06

我不确定数组的数据类型是什么,但这就是如何在 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

I am not certain what is the data-type of array, but this how you manipulate the multi-dimension arrays in VB.NET assuming data-type as object

' 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

See this MSDN article for array in VB.NET: http://msdn.microsoft.com/en-us/library/wak0wfyt.aspx

半山落雨半山空 2024-12-10 02:37:06

试试这个,

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

或者使用

For Each arr As Object(,) In NoOfAdjType

Next

Try this,

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

Or use

For Each arr As Object(,) In NoOfAdjType

Next
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文