0

I'm trying (using SQL and VB.Net) to get a list of dates and strings (representing a film name) using a SELECT command, and then look through each of the 'dates' in the list, one after the other. Like a 'FOR EACH' loop.

I'm not entirely sure how to do this, but here's what I have so far:

    Dim Con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;DataSource=ApplicationData.accdb;Persist Security Info=False;")
    Con.Open() 'Open the connection
    Dim Cmd As New OleDbCommand("SELECT fDateAdded, fName FROM Films", Con)

    Cmd.CommandType = CommandType.Text
    Dim Rdr As OleDbDataReader = Cmd.ExecuteReader()
    Dim schemaTable As DataTable = Rdr.GetSchemaTable()

    Dim row As DataRow
    Dim column As DataColumn

    For Each row In schemaTable.Rows
        For Each column In schemaTable.Columns
            ' WHAT TO DO HERE?
        Next
    Next

How can I go about achieving my goal?

2
  • Not sure what you want to do exactly. Looks like you want to go through each column and check if its the date column. You don't need to do that. The select statement shows that the first column will be date so you can look up row item directly. If the date matches your criteria then you can also access the other row item (fName) and do what you need. If its doesn't then just skip to next row Commented Dec 10, 2013 at 12:07
  • Fantastic! How could I do this in VB.net code? Commented Dec 10, 2013 at 12:14

1 Answer 1

1

Your for-next loop should be something like this...

For Each row As DataRow In dtDataTable.Rows
    If row.Item("fDateAdded") = *your match criteria* Then
        *Do something - you can utilies* row.Item("fName") *if you need*
    End if
Next row

The match criteria can of course be anything < <= > >= or a combination to give you a range etc.

Hope that helps.

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

Comments

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.