Problem adding rows to datatable

  • Thread starter Thread starter Sergio Florez M.
  • Start date Start date
S

Sergio Florez M.

This code gives me an error that says something like "This row already belongs to another table"

//create new row
DataRow ldrInterna = objCliente.PubRDirecciones.NewRow();

//assign values
ldrInterna["DIR_IdMunicipio"] = 1;
ldrInterna["DIR_IdDepartamento"] = 5;
ldrInterna["DIR_IdPersona"] = objCliente.PubRIdPersona;

//add row
objCliente.PubRDirecciones.Rows.Add(ldrInterna.ItemArray);

So what's wrong?
 
Sergio:

I got the code to work for me.. I just made three columns and used the
indexes and then used objCliente.PubRDirecciones.Rows.Add(ldrInterna);

I'm not familiar with using ItemArray in this context, but ldrInterna is a
DataRow so you can just add it directly to the datatable's rows collection.
See if that doesn't fix it b/c it's working fine for me.

Let me know ..

Bill
This code gives me an error that says something like "This row already
belongs to another table"

//create new row
DataRow ldrInterna = objCliente.PubRDirecciones.NewRow();

//assign values
ldrInterna["DIR_IdMunicipio"] = 1;
ldrInterna["DIR_IdDepartamento"] = 5;
ldrInterna["DIR_IdPersona"] = objCliente.PubRIdPersona;

//add row
objCliente.PubRDirecciones.Rows.Add(ldrInterna.ItemArray);

So what's wrong?
 
I decided to use a temp table instead of directly using the one exposed by the class and it works now. Thanks.
 
Back
Top