Reputation: 3431
How can avoid the error "The DataTable is assigned to other DataSet", because the method "RetornarReporteErroresBoleta" is adding the Datatable into a DataSet, then, when the method "RetornarBoletasPorASA" get the DataTable and try to insert into a new DataSet occurs this error. So how can I fix this??
public DataTable RetornarReporteErroresBoleta(SqlString idBoleta)
{
DataTable tablaErrores = new DataTable();
string procedimiento = "paBltMarcarErroresBoleta";
try
{
Database accesoBd = this.gBaseDatosCnx.GenerarAccesoBaseDatosSgapa();
object[] parametros = { idBoleta.Value };
DataSet dsResultado = accesoBd.ExecuteDataSet(procedimiento, parametros);
int cantidadFilas = dsResultado.Tables[0].Rows.Count;
tablaErrores = dsResultado.Tables[0];
}
catch (Exception exc)
{
string mensaje = "Mensaje: " + exc.Message + "\n";
mensaje += "Origen: " + exc.Source + "\n";
mensaje += "Pila: " + exc.StackTrace;
try
{
clsCorreoCom correo = new clsCorreoCom();
string titulo = "Problema en: " + procedimiento;
correo.enviarCorreo(titulo, mensaje, clsCorreoCom.MENSAJE_ERROR);
}
catch (Exception) { }
}
return tablaErrores;
}
public DataSet RetornarBoletasPorASA(SqlString idASA)
{
DataSet erroresBoleta = new DataSet();
string procedimiento = "paBltBuscarBoletasASA";
try
{
Database accesoBd = this.gBaseDatosCnx.GenerarAccesoBaseDatosSgapa();
object[] parametros = { idASA.Value };
DataSet dsResultado = accesoBd.ExecuteDataSet(procedimiento, parametros);
int cantidadFilas = dsResultado.Tables[0].Rows.Count;
foreach (DataRow fila in dsResultado.Tables[0].Rows)
{
string idBoleta = fila[1].ToString();
DataTable tablaErrores = RetornarReporteErroresBoleta(idBoleta);
erroresBoleta.Tables.Add(tablaErrores);
}
}
catch (Exception exc)
{
string mensaje = "Mensaje: " + exc.Message + "\n";
mensaje += "Origen: " + exc.Source + "\n";
mensaje += "Pila: " + exc.StackTrace;
try
{
clsCorreoCom correo = new clsCorreoCom();
string titulo = "Problema en: " + procedimiento;
correo.enviarCorreo(titulo, mensaje, clsCorreoCom.MENSAJE_ERROR);
}
catch (Exception) { }
}
return erroresBoleta;
}
Upvotes: 0
Views: 191
Reputation: 185643
You can't add a DataTable
to more than one DataSet
. Try this instead:
erroresBoleta.Tables.Add(tablaErrores.Copy());
Upvotes: 3