By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,903 Members | 1,677 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,903 IT Pros & Developers. It's quick & easy.

DataRow - SetValue donīt work

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.