0

有人可以帮忙吗-以前我将其存储在数据库中

File Name - Order.csv 
File Arrival Time - 03:00
File Arrival End time - 04:00

但是现在我需要将其从数据库中移出并使用多维数组来存储值,然后遍历它们以检查文件是否已到达。

我有检查文件存在的代码,但我是 vb.net 的新手,所以现在不知道如何将它存储在多维数组中,然后遍历它。

请帮忙。

4

1 回答 1

2

如果你真的想使用数组,你可以尝试类似:

Dim data(,,) As String
ReDim data(10, 10, 10) ' three dimensions
For i As Integer = 0 To data.GetUpperBound(0)
    For j As Integer = 0 To data.GetUpperBound(1)
        For k As Integer = 0 To data.GetUpperBound(2)
           ' do your stuff here
        Next
    Next
Next

但是,为什么不使用对象和列表呢?就像是:

Public Class MyFile
    Property Name As String
    Property ArrivalTime As DateTime
    Property EndTime As DateTime
End Class

' then store the data in a list(of MyFile):
Public Class Test
    Sub LoadingData()
        Dim myData = New List(Of MyFile)
        Using conn As New SqlClient.SqlConnection("your connection string here")
            Using cmd As New SqlClient.SqlCommand()
                cmd.Connection = conn
                cmd.CommandText = "SELECT top 100 Name, ArrivalTime, EndTime FROM yourTable"
                conn.Open()
                Using rdr As SqlClient.SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
                    Dim namePos = rdr.GetOrdinal("Name")
                    Dim timePos = rdr.GetOrdinal("Time")
                    Dim endTimePos = rdr.GetOrdinal("EndTime")
                    While rdr.Read()
                        myData.Add(New MyFile With {.Name = rdr.GetString(namePos),
                                                   .ArrivalTime = rdr.GetDateTime(timePos),
                                                   .EndTime = rdr.GetDateTime(endTimePos)})
                    End While
                End Using
            End Using
        End Using

        For Each item In myData
            ' Do whatever you like with each item
            Console.WriteLine(String.Format("Name: {0}, Arrival Time: {1:yyyy-MM-dd HH:mm:ss}, End Time: {2:yyyy-MM-dd HH:mm:ss}",
                                            item.Name,
                                            item.ArrivalTime,
                                            item.EndTime))
        Next
    End Sub
End Class

-- 只是一个简单的示例,未经测试,您可以根据需要进行调整)...

于 2013-08-14T05:12:59.670 回答