Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IndexOutOfRangeException of DataRow

Status
Not open for further replies.

maccarone

Technical User
Jun 20, 2002
17
IT
Hi,
I'm using in memory DataTable and I would check if a specific value exist in the table (using the primary key already defined) to update a record.

I have a table named Test with 2 different field: test_id and number_occurrences

Dim record_to_find(() as DataRow
record_to_find = test_table.Select("Test_id" = value_to_be_find)

if (test to check if value_to_be_find" has been found in the DataTable) then
' updating the table
record_to_find(0)("number_occurrences") = 100
Else
DO nothing
End If

this because not only value_to_be_find are present into the DataTable, before update table I should check if the select has returned a valid record, because otherwise I get an IndexOutOfRangeException error.
I tried different solution but I'm not able to execute the update only for the found record.

Thanks

Massimo


 
It looks like record_to_find is an array, so use the Length property of the Array class.

Change this

if (test to check if value_to_be_find" has been found in the DataTable) then

to this

If record_to_find.Length > 0 Then 'if no records are found, the array length will be zero


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
I found the solution using GetUpperBound(0)<> -1, and it works fine.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top