Value in DataTable not changing when new value assigned

J

John Dinning

VS2005, C#, Win CE 5.

I have a very strange problem which must have a simple answer. I am new to
..NET.

I am reading a simple XML file into a DataSet (1 table, 5 rows, 2 string
fields per row).
This works ok, I can see the data in the debugger QuickWatch window.

I want to change the value of a string field in the DataSet table currently
set to "123":

MyDataTable.Rows[2].ItemArray[1] = "xyz"

It does not change! It is still "123" immediately after this line and no
exception.
The RowState before and after this line is "Unchanged"

How can this be?
The DataSet is not read only (and I assume if it was, then an exception
would be generated when trying to change the value).

Any help extremely welcome.

John.
 
J

John Dinning

Thanks for the quick response but the computer says:

'System.Data.DataRow' does not contain a definition for 'Item'

John.

Instead of ItemArray, use Item property -->

MyDataTable.Rows[2].Item[1] = "xyz"
 
J

John Dinning

Problem solved. The tidier way to do it:

DataRow["ColName"] = "xyz";

Works fine. I can't say I understand why the other method doesn't.
Learners beware of copying code snippets off the net and assuming they have
been debugged!

John.
 

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

Top