0

Can some please help- Previously I was storing this in database

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

But now I need to move this out from database and using MULTI-DIMENSIONAL ARRAY to store values and then iterate through them to check if files has arrived.

I have the code to check for file existance but im new to vb.net so don't now how to store this in multi-dimensional array and then iterate through it.

Please help.

1
  • may you plz give alittle more insight into the problem e.g the current code u are using,how many fields you are expecting from the DB because Rex 's answer looks pretty ok Commented Aug 14, 2013 at 5:57

1 Answer 1

2

if you really want to use arrays, you could try something like:

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

But, why not use object and list instead? something like:

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

-- just a quick sample, not tested, you may tweak according to your needs)...

Sign up to request clarification or add additional context in comments.

1 Comment

I need to add code in SSIS Package - Script component using Vb.Net. As im new can you please suggest you mention code in FOR each LOOP also please...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.