Well my problem is as follows, I have to save a datatble with several records between them some dates, and I try to save them through a stored procedure that executes a table-type variable that is where I deposit all my values. all the code well except for the dates, although if I insert it manually if you access.
Sp call code:
#region Insert_RectificacionesExportaciones
public string Insert_RectificacionesExportaciones(DataTable dt_rectificacionesExportaciones, string empresa)
{
establecerConexion();
try
{
int idEmpresa = Convert.ToInt16(empresa);
comando = new SqlCommand("sp_Insert_RectificacionesExportaciones", conexion);
comando.CommandType = CommandType.StoredProcedure;
comando.Parameters.AddWithValue("@tblRectificacionesExportaciones", dt_rectificacionesExportaciones);
comando.Parameters.Add("@idEmpresa", SqlDbType.Int).Value = idEmpresa;
comando.CommandTimeout = 7200000;
conexion.Open();
comando.ExecuteReader();
return "1";
}
catch (SqlException ex)
{
return "0";
}
finally
{
if (comando != null)
comando.Dispose();
conexion.Close();
}
}
#endregion
SP code in BD:
USE [DBSIADANA]
GO
/****** Object: StoredProcedure [dbo].[sp_Insert_RectificacionesExportaciones] Script Date: 03/16/2017 12:40:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_Insert_RectificacionesExportaciones]
@tblRectificacionesExportaciones ExpoType READONLY,
@idEmpresa int
AS
BEGIN
SET NOCOUNT ON;
MERGE INTO texportacion c1
USING @tblRectificacionesExportaciones c2
ON c1.idPedimento = c2.idPedimento
and c1.idProducto = c2.idProducto
and c1.factura = c2.factura
and c1.secuencia= c2.secuencia
WHEN NOT MATCHED THEN
INSERT VALUES(c2.idPedimento,c2.fecha,c2.idCveDocSalida,c2.idTipoCambio,c2.valorComercialUSD,
c2.valorComercialMNX,c2.valorAduanaMNX,c2.observación,c2.dta,c2.prv,c2.factura,c2.cove,
c2.fechaFactura,c2.razonSocialCliente,c2.icoterm,c2.idMoneda,c2.factorMonedaExtranjera,
c2.idProducto,c2.idTipoBien,c2.secuencia,c2.idFraccion,c2.idPaisDestino,c2.idPaisComprador,
c2.idUnidadComercial,c2.cantidad,c2.precioUnitario,c2.idTasa,c2.preferencia,c2.originalRectificado,
c2.descargado,c2.fechaIngreso,c2.fechaActualizacion,c2.idUsuario,c2.ipActualizacion,c2.falta,c2.idRemesa,
c2.numeroPM,c2.fechaRemesa,@idEmpresa);
END
The error that marks me is the following:
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value The data for table-valued parameter "@tblRectificacionesExportaciones" does not conform to the table type of the parameter. The statement has been terminated.
and verify that my date fields are of date type. Some dates are date and other dates are datetime.
Those that are date type date are saved like this:
which are datetime type dates are like this: