views:

3847

answers:

2

I have the following code:

Dim i As Integer = dtResult.Rows.Count
For i = 0 To dtResult.Rows.Count Step 1
    strVerse = blHelper.Highlight(dtResult.Rows(i).ToString, s)
    ' syntax error here
    dtResult.Rows(i) = strVerse 
Next

I want to add a strVerse to the current row.

What am I doing wrong?

+1  A: 

You can access columns by index, by name and some other ways:

dtResult.Rows(i)("columnName") = strVerse

You should probably make sure your DataTable has some columns first...

Ken Browning
+3  A: 

The problem you're running into is that you're trying to replace an entire row object. That is not allowed by the DataTable API. Instead you have to update the values in the columns of a row object. Or add a new row to the collection.

To update the column of a particular row you can access it by name or index. For instance you could write the following code to update the column "Foo" to be the value strVerse

dtResult.Rows(i)("Foo") = strVerse
JaredPar