[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Find value in Datatable loop

Posted on 2009-05-20
4
Medium Priority
?
655 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month20 days, 1 hour left to enroll

872 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