Estoy tratando de insertar el contenido de un DataTable en una tabla de usuario(UDT), el primer registro se inserta sin ningun prolema, cuando envio el siguiente registro me devuelve el error
-2035 que dice que el registro que se intenta insertar ya existe. El codigo es el siguiente
// Metodo para insertar cuotas de los empleados.
private void InsertarCuota(CuotasDAP cuotasM, ConnectSAP sapCN)
{
String errorInsert;
int errorCode;
try
{
oUserTable = sapCN.getCompany().UserTables.Item("CUOTAS_PRESTAMOS");
oUserTable.Code = cuotasM.IdNomina.ToString();
oUserTable.Name = cuotasM.IdNomina.ToString();
oUserTable.UserFields.Fields.Item("U_IDCompania").Value = cuotasM.IdCompany;
oUserTable.UserFields.Fields.Item("U_IDEmpleado").Value = cuotasM.IdEmpleado;
oUserTable.UserFields.Fields.Item("U_Nombre").Value = cuotasM.Nombre;
oUserTable.UserFields.Fields.Item("U_Apellido").Value = cuotasM.Apellido;
oUserTable.UserFields.Fields.Item("U_CedulaEmpleado").Value = cuotasM.CedulaEmpleado;
oUserTable.UserFields.Fields.Item("U_Cuota").Value = cuotasM.Cuota;
oUserTable.UserFields.Fields.Item("U_AplicadoSap").Value = cuotasM.AplicadoSap;
oUserTable.UserFields.Fields.Item("U_FechaCuota").Value = DateTime.Now;
if (oUserTable.Add() == 0)
{
}
else
{
cnSap.getCompany().GetLastError(out errorCode, out errorInsert);
} // Fin del IF-ELSE.
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
} // Fin del metodo InsertarCuota.
// Metodo para enviar cuotas a SAP.
public void EnviarSap()
{
// Cargamos el data table con las cuotas.
DataTable Cuotas = CargarCuotas();
// Realizamos la conexion a SAP.
cnSap.connectionBO(2);
if (cnSap.getConnectionResult() == 0)
{
// Recorremos los registros del data table.
foreach (DataRow row in Cuotas.Rows)
{
// Usamos el constructor para recibir los parametros del datatable.
cuotasDap = new CuotasDAP(int.Parse(row["Codigo_nomina"].ToString()), int.Parse(row["dne_CodCompania"].ToString()),
int.Parse(row["Codigo_empleado"].ToString()), row["Nombre"].ToString(), row["Apellido1"].ToString(), row["Cedula"].ToString(),
double.Parse(row["Valor"].ToString()), row["AplicadoSap"].ToString(), DateTime.Parse(row["Fecha_cuota"].ToString()));
InsertarCuota(cuotasDap, cnSap);
} // Fin del foreach.
}
else
{
cnSap.getMessageError();
} // Fin del else IF.