Changing values in DataRow

A

Alen Oblak

Hi

How can I change some values in the DataRow? I make a query to get some
records out of database and then I want to change some, but it doesn't seem
to work. With the following code, nothing gets set:

foreach(DataRow myRow in Table1.Rows)
myRow.ItemArray.SetValue("overwritten value", 0)

myRow contains 3 columns and I would like to change the first one - index 0.

Please help,
Alen
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Alen,
myRow.ItemArray.SetValue("overwritten value", 0)

This should work:

myRow.BeginEdit()
myRow.Item(0) = "overwritten value"
myRow.EndEdit()
 
A

Alen Oblak

myRow doesn't contain a definition for Item, so it doesn't work.

Dmitriy Lapshin said:
Hi Alen,
myRow.ItemArray.SetValue("overwritten value", 0)

This should work:

myRow.BeginEdit()
myRow.Item(0) = "overwritten value"
myRow.EndEdit()

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Alen Oblak said:
Hi

How can I change some values in the DataRow? I make a query to get some
records out of database and then I want to change some, but it doesn't seem
to work. With the following code, nothing gets set:

foreach(DataRow myRow in Table1.Rows)
myRow.ItemArray.SetValue("overwritten value", 0)

myRow contains 3 columns and I would like to change the first one -
index
0.

Please help,
Alen
 
D

Dmitriy Lapshin [C# / .NET MVP]

Correction:

You should write

myRow(0) = "overwritten value"

since Item is the default property.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Alen Oblak said:
myRow doesn't contain a definition for Item, so it doesn't work.

Dmitriy Lapshin said:
Hi Alen,
myRow.ItemArray.SetValue("overwritten value", 0)

This should work:

myRow.BeginEdit()
myRow.Item(0) = "overwritten value"
myRow.EndEdit()

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Alen Oblak said:
Hi

How can I change some values in the DataRow? I make a query to get some
records out of database and then I want to change some, but it doesn't seem
to work. With the following code, nothing gets set:

foreach(DataRow myRow in Table1.Rows)
myRow.ItemArray.SetValue("overwritten value", 0)

myRow contains 3 columns and I would like to change the first one -
index
0.

Please help,
Alen
 
A

Alen Oblak

Thanks! It works!

Dmitriy Lapshin said:
Correction:

You should write

myRow(0) = "overwritten value"

since Item is the default property.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Alen Oblak said:
myRow doesn't contain a definition for Item, so it doesn't work.

in message news:#[email protected]...
Hi Alen,

myRow.ItemArray.SetValue("overwritten value", 0)

This should work:

myRow.BeginEdit()
myRow.Item(0) = "overwritten value"
myRow.EndEdit()

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Hi

How can I change some values in the DataRow? I make a query to get some
records out of database and then I want to change some, but it doesn't
seem
to work. With the following code, nothing gets set:

foreach(DataRow myRow in Table1.Rows)
myRow.ItemArray.SetValue("overwritten value", 0)

myRow contains 3 columns and I would like to change the first one - index
0.

Please help,
Alen
 

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

Top