I have a DataTable and I am looping it as follows:
For Each row As DataRow In odds.Rows
gameDesc = row.Item("OutComeGameDesc")
game = row.Item("OutComeGame")
gameCode = row.Item("OutComeGameCode")
odd = row.Item("OutComeOdd")
If gameDesc.Contains("FINAL RESULT") Then
If Trim(game) = "1" Then
finalscorehomecode.InnerHtml = gameCode
finalscorehomeodd.InnerHtml = odd
ElseIf Trim(game) = "X" Then
finalscoredrawcode.InnerHtml = gameCode
finalscoredrawodd.InnerHtml = odd
ElseIf Trim(game) = "2" Then
finalscoreawaycode.InnerHtml = gameCode
finalscoreawayodd.InnerHtml = odd
End If
End If
Next row
I wonder if I can only loop through for a specific data on a column. Lets say I want to loop only the column OutComeGameDesc that has FINAL RESULT in it.
Is there a way to do it?
Best Regards.
Keep your friends close and your enemies even closer
cenk1536
Contributor
2503 Points
2123 Posts
Loop through DataTable According to a specific data on a column?
May 09, 2012 01:43 PM|LINK
Hi,
I have a DataTable and I am looping it as follows:
For Each row As DataRow In odds.Rows gameDesc = row.Item("OutComeGameDesc") game = row.Item("OutComeGame") gameCode = row.Item("OutComeGameCode") odd = row.Item("OutComeOdd") If gameDesc.Contains("FINAL RESULT") Then If Trim(game) = "1" Then finalscorehomecode.InnerHtml = gameCode finalscorehomeodd.InnerHtml = odd ElseIf Trim(game) = "X" Then finalscoredrawcode.InnerHtml = gameCode finalscoredrawodd.InnerHtml = odd ElseIf Trim(game) = "2" Then finalscoreawaycode.InnerHtml = gameCode finalscoreawayodd.InnerHtml = odd End If End If Next rowI wonder if I can only loop through for a specific data on a column. Lets say I want to loop only the column OutComeGameDesc that has FINAL RESULT in it.
Is there a way to do it?
Best Regards.
Mastan Oli
Contributor
5100 Points
999 Posts
Re: Loop through DataTable According to a specific data on a column?
May 09, 2012 02:16 PM|LINK
You can very easy, like
For Each row As DataRow In odds.Select("OutComeGameDesc = 'FINAL RESULT'")
...
playingOOPS | மெய்ப்பொருள் காண்பதறிவு
Mark as Answer If you find helpful
cenk1536
Contributor
2503 Points
2123 Posts
Re: Loop through DataTable According to a specific data on a column?
May 09, 2012 05:48 PM|LINK
Hi Mastan Oli,
Thanks for your reply. I also find how to filter for multiple columns etc.
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx