Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / October 2006

Tip: Looking for answers? Try searching our database.

How do I change a value of a DataTable cell in a DataSet? (C#)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pavel Maly - 28 Oct 2006 14:46 GMT
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
Pavel Maly - 28 Oct 2006 15:23 GMT
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):
> Hello everyone,
> as a beginner I've encountered a problem while trying to change a value inside the DataSet.
[quoted text clipped - 15 lines]
>
> Pavel
Chris Bordeman - 29 Oct 2006 08:01 GMT
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.

> Well, another thorough googling revealed a method which seems to work
> fine:
[quoted text clipped - 33 lines]
>>
>> Pavel
Pavel Maly - 29 Oct 2006 08:50 GMT
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):
> If it's a 2.0 typed dataset you can use Rows[0].Fieldname = "something";
>
[quoted text clipped - 38 lines]
>>>
>>> Pavel

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.