Why doesnt this work (just ONE line)

  • Thread starter Thread starter Ibai Peña
  • Start date Start date
I

Ibai Peña

I have tried to asign a value to a element of an ItemArray using 2 different
ways.

NewRow.ItemArray.SetValue(Int64.Parse(txtExist.Text),4);
or
NewRow.ItemArray[4] = Int64.Parse(txtExist.Text);

But the elements value doesnt change (DBNull).
Could someone explain me why?

Thanks,
 
I answer myself.

looks like is not possible to change only one element of the ItemArray. The
good way is to asign all the array. Somethin like:

object [] myArray = new object[5];
myArray[0] = TInventario.Rows.ItemArray[0];
myArray[1] = TInventario.Rows.ItemArray[1];
myArray[2] = TInventario.Rows.ItemArray[2];
myArray[3] = TInventario.Rows.ItemArray[3];
myArray[4] = txtExist.Text;

TInventario.Rows.ItemArray = myArray;

Regards,
 
Consider using DataTable.LoadRow() method instead

Ibai Peña said:
I answer myself.

looks like is not possible to change only one element of the ItemArray. The
good way is to asign all the array. Somethin like:

object [] myArray = new object[5];
myArray[0] = TInventario.Rows.ItemArray[0];
myArray[1] = TInventario.Rows.ItemArray[1];
myArray[2] = TInventario.Rows.ItemArray[2];
myArray[3] = TInventario.Rows.ItemArray[3];
myArray[4] = txtExist.Text;

TInventario.Rows.ItemArray = myArray;

Regards,
--
Ibai Peña

Ibai Peña said:
I have tried to asign a value to a element of an ItemArray using 2 different
ways.

NewRow.ItemArray.SetValue(Int64.Parse(txtExist.Text),4);
or
NewRow.ItemArray[4] = Int64.Parse(txtExist.Text);

But the elements value doesnt change (DBNull).
Could someone explain me why?

Thanks,
 
Back
Top