Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/10/2010, 09:39
menesesc
 
Fecha de Ingreso: noviembre-2009
Mensajes: 2
Antigüedad: 14 años, 5 meses
Puntos: 0
Exclamación Problema con fechas y proc almacenado

Buenos dias
Hace varios dias estoy peleando con un problema que no puedo resolver.
Estoy desarrollando en VB 2005 y SQL Server 2005. Tengo una clase para
manejar los procedimientos almacenados y en el momento de hacer un
ExecuteReader me da un error "error converting data type varchar to
smalldatetime"
Si ejecuto el procedimiento almacenado desde SQL Server no me da
ningun tipo de error. Paso a dar el codigo fuente.

PROCEDIMIENTO ALMACENADO
--------------------------------------------------------------------------- --------
ALTER PROCEDURE [dbo].[CrearCaja]
(
@IDCaja INT = NULL OUTPUT,
@IDUsuario tinyint,
@IDTipoCaja TINYINT,
@Fecha smalldatetime
)
AS
DECLARE @IDUltimaCaja INT
SET @IDUltimaCaja = (SELECT TOP 1 IDCaja FROM Cajas WHERE IDTipoCaja =
@IDTipoCaja ORDER BY Fecha DESC)
if NOT (object_id('tempdb.dbo.#SALDO') is null)
DROP TABLE #SALDO
CREATE TABLE #SALDO
(
IDMoneda tinyint,
Moneda varchar(50),
Saldo money,
UltimaFechaMov smalldatetime,
UltimaFechaTra smalldatetime,
Alerta bit
)
--BUSCA SALDO FINAL
TRUNCATE TABLE #SALDO
INSERT INTO #SALDO EXEC GETSaldosCajas @IDUltimaCaja
DELETE #SALDO WHERE Saldo = 0
--CREA NUEVA CAJA
INSERT INTO Cajas (IDTipoCaja, IDUsuario, Fecha, Bloqueado, Eliminado)
VALUES
(@IDTipoCaja, @IDUsuario, @Fecha2, 0, 0)
SET @IDCaja = SCOPE_IDENTITY();
--CREA SALDO INICIAL
INSERT INTO Saldos
SELECT
@IDCaja AS IDCaja,
A.IDMoneda,
@Fecha2 AS Fecha,
A.Saldo,
1 AS Inicial,
0 AS Eliminado
FROM #SALDO A
--DEVUELVE ID DE CAJA CREADA O CERO SI HAY ERROR
IF ISNULL(@@ERROR, 0) = 0
SELECT @IDCaja
ELSE
SELECT 0
CLASE DEL PROCEDIMIENTO EN VB 2005
--------------------------------------------------------------------------- -
Public NotInheritable Class CrearCaja
Inherits StoredProcedure
Public Sub New()
MyBase.New("[dbo].[CrearCaja]")
Me.CreateParameters
End Sub
Public Sub New(ByVal Connection As SqlConnection)
MyBase.New("[dbo].[CrearCaja]", Connection)
Me.CreateParameters
End Sub
Public Sub New(ByVal Transaction As SqlTransaction)
MyBase.New("[dbo].[CrearCaja]", Transaction)
Me.CreateParameters
End Sub
Public Property IDCaja() As System.Nullable(Of Integer)
Get
Return CType(Me(1),System.Nullable(Of Integer))
End Get
Set
Me(1) = value
End Set
End Property
Public Property IDUsuario() As System.Nullable(Of Byte)
Get
Return CType(Me(2),System.Nullable(Of Byte))
End Get
Set
Me(2) = value
End Set
End Property
Public Property IDTipoCaja() As System.Nullable(Of Byte)
Get
Return CType(Me(3),System.Nullable(Of Byte))
End Get
Set
Me(3) = value
End Set
End Property
Public Property Fecha() As System.Nullable(Of Date)
Get
Return CType(Me(4),System.Nullable(Of Date))
End Get
Set
Me(4) = value
End Set
End Property
Private Sub CreateParameters()
Dim param As SqlParameter
param = New SqlParameter("@IDCaja", SqlDbType.Int)
param.Direction =
System.Data.ParameterDirection.InputOutput
param.SourceColumn = "IDCaja"
Me.Parameters.Add(param)
param = New SqlParameter("@IDUsuario", SqlDbType.TinyInt)
param.SourceColumn = "IDUsuario"
Me.Parameters.Add(param)
param = New SqlParameter("@IDTipoCaja", SqlDbType.TinyInt)
param.SourceColumn = "IDTipoCaja"
Me.Parameters.Add(param)
param = New SqlParameter("@Fecha",
SqlDbType.SmallDateTime)
param.SourceColumn = "Fecha"
Me.Parameters.Add(param)
End Sub
Public Overloads Function ExecuteNonQuery(ByVal IDCaja As
System.Nullable(Of Integer), ByVal IDUsuario As System.Nullable(Of
Byte), ByVal IDTipoCaja As System.Nullable(Of Byte), ByVal Fecha As
System.Nullable(Of Date)) As Integer
Return MyBase.ExecuteNonQuery(IDCaja, IDUsuario,
IDTipoCaja, Fecha)
End Function
Public Overloads Function ExecuteScalar(ByVal IDCaja As
System.Nullable(Of Integer), ByVal IDUsuario As System.Nullable(Of
Byte), ByVal IDTipoCaja As System.Nullable(Of Byte), ByVal Fecha As
System.Nullable(Of Date)) As Object
Return MyBase.ExecuteScalar(IDCaja, IDUsuario, IDTipoCaja,
Fecha)
End Function
Public Overloads Function ExecuteReader(ByVal IDCaja As
System.Nullable(Of Integer), ByVal IDUsuario As System.Nullable(Of
Byte), ByVal IDTipoCaja As System.Nullable(Of Byte), ByVal Fecha As
System.Nullable(Of Date)) As SqlDataReader
Return MyBase.ExecuteReader(IDCaja, IDUsuario, IDTipoCaja,
Fecha)
End Function
Public Overloads Function ExecuteXmlReader(ByVal IDCaja As
System.Nullable(Of Integer), ByVal IDUsuario As System.Nullable(Of
Byte), ByVal IDTipoCaja As System.Nullable(Of Byte), ByVal Fecha As
System.Nullable(Of Date)) As XmlReader
Return MyBase.ExecuteXmlReader(IDCaja, IDUsuario,
IDTipoCaja, Fecha)
End Function
Public Overloads Sub SetParameters(ByVal IDCaja As
System.Nullable(Of Integer), ByVal IDUsuario As System.Nullable(Of
Byte), ByVal IDTipoCaja As System.Nullable(Of Byte), ByVal Fecha As
System.Nullable(Of Date))
MyBase.SetParameters(IDCaja, IDUsuario, IDTipoCaja, Fecha)
End Sub
Public Overloads Sub LoadTable(ByVal Table As DataTable, ByVal
IDCaja As System.Nullable(Of Integer), ByVal IDUsuario As
System.Nullable(Of Byte), ByVal IDTipoCaja As System.Nullable(Of
Byte), ByVal Fecha As System.Nullable(Of Date))
MyBase.LoadTable(Table, IDCaja, IDUsuario, IDTipoCaja,
Fecha)
End Sub
End Class


CODIGO VB 2005
------------------------------------------
Dim Fecha as date
'CONVIERTE FECHA STRING A DATE -- 22/06/2010 -> #06/22/2010#
Fecha = DateTime.Parse(Mid(Grid.Rows(i).Item(0), 7, 2) & "/" &
Mid(Grid.Rows(i).Item(0), 5, 2) & "/" & Mid(Grid.Rows(i).Item(0), 1,
4), Globalization.CultureInfo.CreateSpecificCulture("e s"))
'AQUI LLAMA A LA FUNCION ALTACAJA
IDCaja = AltaCaja(IDTipoCaja, Fecha)
' FUNCION ALTACAJA
Private Function AltaCaja(ByVal IDTipoCaja As Byte, ByVal Fecha As
Date) As Integer
Try
Dim CrearCaja As New CrearCaja(GralConexion) 'CREA
PARAMETROS
Dim Dev As SqlDataReader
Dev = CrearCaja.ExecuteReader(1, 1, IDTipoCaja, Fecha)
'AQUI SE GENERA EL ERROR
AltaCaja = 1
While Dev.Read
AltaCaja = Dev(0)
End While
Dev.Close()
Catch
MsgBox(Err.Description)
AltaCaja = 1
End Try
End Function
Eso es todo, espero que alguien pueda ayudarme ya que no le encuentro
explicacion al error. Muchas gracias de antemano. Saludos


Cristian Meneses