Groups | Blog | Home
all groups > dotnet windows forms databinding > october 2006 >

dotnet windows forms databinding : How do I change a value of a DataTable cell in a DataSet? (C#)



Pavel Maly
10/28/2006 3:46:37 PM
Hello everyone,
as a beginner I've encountered a problem while trying to change a value inside the DataSet.
After I call

dataSet.Tables["tbl"].Rows[0].ItemArray.SetValue("something", colIdx);

the value in the row 0 and column colIdx of the DataTable "tbl" doesn't get changed.

The thing is I need to change a few values after loading the database file data into the DataSet
and, as I've read somewhere, it is necessary to change the data in the DataSet, then set the
DataSource property to null and reassign it again to see the changed values. I've tried to
change the content of data-bound controls directly, but that didn't work every time (it failed,
for instance, in case the control was on a TabPage which was not selected).

How should I change the value correctly then?

TIA

Pavel Maly
10/28/2006 4:23:37 PM
Well, another thorough googling revealed a method which seems to work fine:

dataSet.Tables["tbl"].Rows[0][colIdx] = "something";

Nevertheless, in case anyone knows a better method, I'll be glad to know it too... :)

Pavel



Pavel Maly napsal(a):
[quoted text, click to view]
Pavel Maly
10/29/2006 12:00:00 AM
Hello Chris,
thank you for your response. Unfortunately, since the data structure might be different in
different files, the DataSet may not be a typed one.

Nevertheless, it is always good to know more... :)

Pavel


Chris Bordeman napsal(a):
[quoted text, click to view]
Chris Bordeman
10/29/2006 1:01:30 AM
If it's a 2.0 typed dataset you can use Rows[0].Fieldname = "something";

Provides type safety and more convenient. Use the Data-->Add new data
source wizard.

[quoted text, click to view]

AddThis Social Bookmark Button