Visual Basic - Stored Procedure de VB a SQL. Prob. con datetime

Life is soft - evento anual de software empresarial
 
Vista:

Stored Procedure de VB a SQL. Prob. con datetime

Publicado por Marcelo (1 intervención) el 03/10/2005 15:44:54
Quería consultartes sobre un problema que tengo. Tengo un Stored procedured que no me está respondiendo desde VB. El SP simplemente contiene un query con un parametro tipo datetime. Si hago el query desde el query analyzer me funciona bien.
Espero me puedan ayudar,

Este es el código:

SQL Stored Procedure

CREATE PROCEDURE dbo.GetMovimiento
@FechaVenc datetime
AS
SET NOCOUNT ON;
SELECT rem,mart,unid,descr,canti,mcli,fvenc FROM mer WHERE fvenc=@FechaVenc ORDER BY mart
GO

Visual Basic Code
Private Sub cmdListar_Click()
Dim lDatFechaVencimiento As Date
lDatFechaVencimiento = CDate(Me.txtFechaVencimiento)
CargarDatos (lDatFechaVencimiento)
End Sub

Sub CargarDatos(parDatFechaVenc As Date)
Dim itmX As ListItem
On Error GoTo ErrorHandler

Dim cnn1 As ADODB.Connection
Dim cmd1 As ADODB.Command
Dim rst1 As ADODB.Recordset
Dim prm1 As ADODB.Parameter
Dim strCnn As String
Dim strSQL As String
Dim strSPMovimiento As String

' Open connection
Set cnn1 = New ADODB.Connection
strCnn = "Provider='sqloledb';Data Source='madsrv006';" & _
"Initial Catalog='Lince';Integrated Security='SSPI';"
cnn1.Open strCnn
cnn1.CursorLocation = adUseClient

' Open command object with one parameter
Set cmd1 = New ADODB.Command
cmd1.ActiveConnection = cnn1
strSPMovimiento = "getMovimiento"
cmd1.CommandText = strSPMovimiento
cmd1.CommandType = adCmdStoredProc
cmd1.CommandTimeout = 15

' Define the stored procedure's input parameter
Set prm1 = New ADODB.Parameter
prm1.Type = adInteger
prm1.Size = 3
prm1.Direction = adParamInput
prm1.Value = parDatFechaVenc

cmd1.Parameters.Append prm1

lvwMovimiento.ListItems.Clear

' Create a recordset by executing the command.
Set rst1 = New ADODB.Recordset
Set rst1 = cmd1.Execute()

Do While Not rst1.EOF

If Not IsNull(rst1!REM) Then

Set itmX = lvwMovimiento.ListItems.Add(, , rst1!REM)
If Not IsNull(rst1!Mart) Then
itmX.SubItems(1) = rst1!Mart
End If
If Not IsNull(rst1!Unid) Then
itmX.SubItems(2) = rst1!Unid
End If
If Not IsNull(rst1!Descr) Then
itmX.SubItems(3) = rst1!Descr
End If
If Not IsNull(rst1!Canti) Then
itmX.SubItems(4) = rst1!Canti
End If
If Not IsNull(rst1!Mcli) Then
itmX.SubItems(5) = rst1!Mcli
End If
If Not IsNull(rst1!Fvenc) Then
itmX.SubItems(6) = rst1!Fvenc
End If
End If
rst1.MoveNext
'DoEvents
Loop

' clean up
rst1.Close
cnn1.Close
Set rst1 = Nothing
Set cnn1 = Nothing
Exit Sub

ErrorHandler:
' clean up
If Not rst1 Is Nothing Then
If rst1.State = adStateOpen Then rst1.Close
End If
Set rst1 = Nothing

If Not cnn1 Is Nothing Then
If cnn1.State = adStateOpen Then cnn1.Close
End If
Set cnn1 = Nothing

If Err <> 0 Then
MsgBox "Número de Error: " & Err.Number & vbCr & Err.Source & "-->" & Err.Description, , "Error"
End If

End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder