Solved

Find value in Datatable loop

Posted on 2009-05-20
4
643 Views
Last Modified: 2012-05-07
Im trying to find certain text within column 2 of my datatable. Below is what I have so far but its not finding the values even though they exist. Can anyone help me?
For Each DataRow In AS400DS.Rows

            If AS400DS.Columns(2).ToString = "AB" Then

                Absentee.DataField = "Hours"

            ElseIf AS400DS.Columns(2).ToString = "VA" Then

                Vacation.DataField = "Hours"

            ElseIf AS400DS.Columns(2).ToString = "OT" Then

                OT.DataField = "Hours"

            ElseIf AS400DS.Columns(2).ToString = "WH" Then

                OTx2.DataField = "Hours"

            End If

            Response.Write(AS400DS.Columns(2))

        Next

Open in new window

0
Comment
Question by:ITHelper80
  • 2
4 Comments
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 24433499

For Each oRow As DataRow In AS400DS.Rows
            If oRow (2).ToString = "AB" Then
                Absentee.DataField = "Hours"
            ElseIf oRow (2).ToString = "VA" Then
                Vacation.DataField = "Hours"
            ElseIf oRow (2).ToString = "OT" Then
                OT.DataField = "Hours"
            ElseIf oRow (2).ToString = "WH" Then
                OTx2.DataField = "Hours"
            End If
            Response.Write(oRow(2).ToString)
        Next
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24433519
hi,

try this:
For Each DataRow In AS400DS.Rows

            If LCase(AS400DS.Columns(2).ToString) = LCase("AB") Then

                Absentee.DataField = "Hours"

            ElseIf LCase(AS400DS.Columns(2).ToString) = LCase("VA") Then

                Vacation.DataField = "Hours"

            ElseIf LCase(AS400DS.Columns(2).ToString) = LCase("OT") Then

                OT.DataField = "Hours"

            ElseIf LCase(AS400DS.Columns(2).ToString) = LCase("WH") Then

                OTx2.DataField = "Hours"

            End If

            Response.Write(AS400DS.Columns(2))

        Next

Open in new window

0
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24433527
For Each myRow As DataRow In AS400DS.Rows
                    If myRow .Item(2).ToString = "AB" Then
                Absentee.DataField = "Hours"
Next
0
 
LVL 10

Accepted Solution

by:
MaxOvrdrv2 earned 500 total points
ID: 24433539
crud, sorry, my bad, try this instead:
dim dr as DataRow
 

For Each dr In AS400DS.Rows

            If LCase(dr.Columns(2).ToString) = LCase("AB") Then

                Absentee.DataField = "Hours"

            ElseIf LCase(dr.Columns(2).ToString) = LCase("VA") Then

                Vacation.DataField = "Hours"

            ElseIf LCase(dr.Columns(2).ToString) = LCase("OT") Then

                OT.DataField = "Hours"

            ElseIf LCase(dr.Columns(2).ToString) = LCase("WH") Then

                OTx2.DataField = "Hours"

            End If

            Response.Write(dr.Columns(2))

        Next

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now