A very simple question about assigning a value

  • Thread starter Thread starter Sajid
  • Start date Start date
S

Sajid

Hello,

I have the following case where I want to assign a value to a column
in a row. But it gives me an error that "Property Item is readonly":

DataAdapter.Fill(DataTable1)

Dim clone as DataTable

clone = DataTable1.Clone

For Each row As DataRow In
DataTable1.Select(String.Format("{0}='{1}'", field1, somevalue))

clone.ImportRow(row)

Next

clone.Rows.Item("field2") = "Test"
Here is the problem where it says "Property Item is readonly"

Your kind help will be really appreciated.

cheers

SY
 
You have to do it this way:

clone.Rows(RowNumber)("field2") = "Test"

The "Rows" is the collection of all rows in the table (index starts at 0).
So you have to access one row in the way above by replacing "RowNumber" by
the number of the row in which you wanna assign the value to the field.

Regards,

Peter
 
Ok this is easy.

Your trying to assign a value to a row position not the actual column, or
better the cell.

Off the top of my head:

clone.Rows[index].Columns[index].Text = "Test"

Mind you this syntax is probably wrong but you should get the idea.

Enjoy!!

-Evan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top