Changing values in DataRow

  • Thread starter Thread starter Alen Oblak
  • Start date Start date
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
 
Hi Alen,
myRow.ItemArray.SetValue("overwritten value", 0)

This should work:

myRow.BeginEdit()
myRow.Item(0) = "overwritten value"
myRow.EndEdit()
 
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
 
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
 
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
 
Back
Top