473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

DataRow - SetValue donīt work

Hello Guys,

I need to set a default value in the first column of my
dataTable.
I tried to do it:

foreach (DataRow rowExp in tblExport.Rows)
{
rowExp.ItemArray.SetValue("false", 0);
}

but when I check values in my dataTable I notice nothing
happen (that arenīt any changes)

Anybody can help me ?

Tks

Jean Carlo
(Brazil)
Nov 15 '05 #1
2 20359
Jean,

The reason this doesn't work is that ItemArray returns a copy of the
values in the row, it doesn't return an object where you can set the values
on the row. In order to change the value on a row, you will want to use the
indexer on the row, like this:

// Cycle through all rows.
foreach (DataRow rowExp in tblExport.Rows)
// Set the value of the first column in each row to "false".
rowExp[0] = "false";

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jean" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...
Hello Guys,

I need to set a default value in the first column of my
dataTable.
I tried to do it:

foreach (DataRow rowExp in tblExport.Rows)
{
rowExp.ItemArray.SetValue("false", 0);
}

but when I check values in my dataTable I notice nothing
happen (that arenīt any changes)

Anybody can help me ?

Tks

Jean Carlo
(Brazil)
Nov 15 '05 #2
Thanks Nicholas
I use the indexer and now my application is working
perfect !

Thanks a lot !

Jean Carlo Mendes
:: Brazil ::

-----Original Message-----
Jean,

The reason this doesn't work is that ItemArray returns a copy of thevalues in the row, it doesn't return an object where you can set the valueson the row. In order to change the value on a row, you will want to use theindexer on the row, like this:

// Cycle through all rows.
foreach (DataRow rowExp in tblExport.Rows)
// Set the value of the first column in each row to "false". rowExp[0] = "false";

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jean" <an*******@discussions.microsoft.com> wrote in messagenews:06****************************@phx.gbl...
Hello Guys,

I need to set a default value in the first column of my
dataTable.
I tried to do it:

foreach (DataRow rowExp in tblExport.Rows)
{
rowExp.ItemArray.SetValue("false", 0);
}

but when I check values in my dataTable I notice nothing
happen (that arenīt any changes)

Anybody can help me ?

Tks

Jean Carlo
(Brazil)
.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael | last post by:
Hello, I am trying to add some kind of counter in a datatable, i use SetValue but it don't semm to work. Here is the code System.Data.DataSet dsClubs = new System.Data.DataSet(); ...
3
by: Laurie | last post by:
Hi, I need to be able to manipulate field values within a structure using FieldInfo.GetValue and FieldInfo.SetValue, in VB.Nt 2003. The GetValue is working fine and makes it really easy for me...
15
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is...
2
by: Brent | last post by:
I have variables in a structure loaded into a list box. I thought I could use FieldInfo.SetValue to update the items value when the user clicks on it, but it is not working. .. .. .. Dim fi...
5
by: Dennis | last post by:
I have an array "t" where each element is a structure of type "testing". I want to use the FieldInfo class to set the values of the array element fields. I can read the field properties and...
6
by: Mindy | last post by:
Hey, I am using SetValue to change the DataEntry property of a form to "YES". But It doesn't work. No error messages, but the property didn't change.Following is the what I am writing SetValue:...
0
by: kernell | last post by:
Hi everyone, i'm trying to initialize all control of a UserControl to is appropriate class. The value is set but the event won't raise anymore. See the example: 'Not working 'Normally...
2
by: cwertman | last post by:
Ok, Im missing something simple here. I have an object o its a person , I want to "blank" out any properties that are a type of a collection The follwoing code will loop through and tell me if...
9
by: FourEyes | last post by:
I've read that Reflection is slow and shouldn't be used when performance is a concern. In my case, performance is definitely a concern, so I was thinking that I could collect the PropertyInfo...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.