Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Is there a better way of doing this?

VB
For Each row In licenceTable.Rows
    If row("DriveKey") = selectedKey Then
        row("Location") = selectedLocal
    End If
Next
Posted
Updated 24-Nov-11 20:33pm
v2
Comments
LanFanNinja 25-Nov-11 3:01am    
Well if you only want to modify one row in the loop once it is found and modified you may want to break out of the loop. i.e.
For Each row In licenceTable.Rows
If row("DriveKey") = selectedKey Then
row("Location") = selectedLocal
Exit For
End If
Next
MrZedSven 25-Nov-11 4:13am    
Exit For will help.
I was wondering if you can change the value without looping though the whole
table.
Like SELECT INTO .... WHERE .... in SQL.
This runs on Form.Load and increases the start-up time quite a bit.
thatraja 25-Nov-11 3:19am    
IMO this is almost fine one. Related link

I think this might be faster.

VB
licenceTable.DefaultView.RowFilter = "DriveKey = '" + selectedKey + "'"
For Each row In licenceTable.DefaultView
    row("Location") = selectedLocal
Next


Just remember to set the RowFilter to nothing before referencing the
default view again.

VB
licenceTable.DefaultView.RowFilter = Nothing
 
Share this answer
 
I believe this one is already good enough as per performace.

Goodluck on you. Please share us if you find a better one :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900