Error when changing data value in strongly typed dataset table?

K

Keithb

I am trying to change the value of a field in a table that is a member of
strongly typed DataSet. The code:

foreach (DataRow rw in dt.Rows) {
rw.ItemArray[16] = (string)c3Text;
}

does not change the content of the item.

Using debugging tools to look at rw, I see this message where the data
should be.

"c3LabelText = '((DataSet1.DisplayRow)(rw)).c3LabelText' threw an exception
of type 'System.Data.StrongTypingException'"

What am I doing wrong?

Thanks,

Keith
 
L

LosManos

hejdig.
I am trying to change the value of a field in a table that is a member of
strongly typed DataSet. The code:
foreach (DataRow rw in dt.Rows) {
rw.ItemArray[16] = (string)c3Text;
}
does not change the content of the item.
Using debugging tools to look at rw, I see this message where the data
should be.
"c3LabelText = '((DataSet1.DisplayRow)(rw)).c3LabelText' threw an
exception of type 'System.Data.StrongTypingException'"

If c3Text is a textbox (hard to tell from the variable name) then you
probably want to use c3Text.Text since you otherwise try to cast a TextBox
object to a System.String.

Another possibility, though I doubt it, is that 16 is wrong. It is a large
number and to count to the 17th item (which 16 points to) without jumping
over a column might be tricky.
Couldn't you use something like
rw[ dt.myColumn.ColumnName ] = ....
because then you know you are at the right place.
?

HTH

/OF
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top