Member_2_5230414
asked on
Vb.net Datatable -> if statement to check if the value exists then amend the table
Hi ALL,
Below if the code i have so far and I have 2 questions really....
1) i have an error "BC30311: Value of type 'System.Collections.Generi c.IEnumera ble(Of System.Data.DataRow)' cannot be converted to 'Boolean'." on row If scorestable.Rows.Cast(Of DataRow)().Where(Function( n) n("Score").ToString() = thescorestext then
2) Can i do this with less code and make it quicker/neater?
I have commented the below code to show what i wanted it to do....
Below if the code i have so far and I have 2 questions really....
1) i have an error "BC30311: Value of type 'System.Collections.Generi
2) Can i do this with less code and make it quicker/neater?
I have commented the below code to show what i wanted it to do....
'Check to see if anyrows in HomeTeam contain a value
Dim count = scorestable.Rows.Cast(Of DataRow)().Where(Function(n) n("HomeTeam").ToString() = StringOutNumbers(div.selectSingleNode(".//td[@class='home']").InnerText)).Count()
'Find the count
if count = 0 then
'add row to the datatable as no results where found
scorestable.Rows.Add(StringOutNumbers(div.selectSingleNode(".//td[@class='home']").InnerText), div.selectSingleNode(".//td[@class='time']").InnerText.Trim().Substring(0, 2) , thescorestext)
else
'A matching result was found so now check to see if the Scores section of the result matches the value - thescorestext
If scorestable.Rows.Cast(Of DataRow)().Where(Function(n) n("Score").ToString() = thescorestext then
'Yes it does match the score so we just need to update the column of the row with the correct time
Dim scoresRow() As Data.DataRow
'Make sure i have selected the correct team
scoresRow = scorestable.Select("HomeTeam = StringOutNumbers(div.selectSingleNode(".//td[@class='home']").InnerText)")
'Update the time row'
scoresRow(0)("Time") = div.selectSingleNode(".//td[@class='time']").InnerText.Trim().Substring(0, 2)
else
'The score does not match meaning i need to update both the score and the time
Dim scoresRow() As Data.DataRow
'Make sure i have selected the correct team
scoresRow = scorestable.Select("HomeTeam = StringOutNumbers(div.selectSingleNode(".//td[@class='home']").InnerText)")
'update score
scoresRow(0)("Score") = thescorestext
'Update time
scoresRow(0)("Time") = div.selectSingleNode(".//td[@class='time']").InnerText.Trim().Substring(0, 2)
end if
end if
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try following
scorestable.Rows.Cast(Of DataRow)().Where(Function( n) n("Score").ToString())(0)( "Score") = thescorestext
Another option is to use dataview
scorestable.DefaultView.Ro wFilter = "Score='" & thescorestext & "'"
if scorestable.DefaultView.Co unt > 0 Then
'score found
else
'not found
End If
scorestable.Rows.Cast(Of DataRow)().Where(Function(
Another option is to use dataview
scorestable.DefaultView.Ro
if scorestable.DefaultView.Co
'score found
else
'not found
End If
ASKER