这是正确的,但返回错误代码转换数据类型
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[USp_TB_INFO_Insert]
(@idinfo INT OUTPUT,
@infotext VARCHAR(200) = NULL,
@lpriority INT = NULL,
@sdate_ini CHAR(20) = NULL,
@sdate_end CHAR(20) = NULL,
@active BIT = NULL,
@namefile VARCHAR(100) = NULL,
@fkgroup INT = NULL,
@username VARCHAR(100) = NULL,
@user VARCHAR(200) = NULL,
@log BIT = 1)
AS
BEGIN TRAN
SET NOCOUNT ON;
DECLARE @deleted BIT
DECLARE @date_ini DATETIME
DECLARE @date_end DATETIME
SET @deleted = 0
IF @sdate_ini IS NULL
BEGIN
SET @date_ini = getdate()
END
ELSE
BEGIN
SET @date_ini = CAST(@sdate_ini AS DATETIME)
END
IF @sdate_end IS NULL
BEGIN
SET @date_end = NULL
END
ELSE
BEGIN
SET @date_end = CAST(@sdate_end AS DATETIME)
END
INSERT INTO [dbo].[TB_INFO] ([infotext], [lpriority], [date_ini], [date_end],
[active], [namefile], [fkgroup], [deleted], [username])
VALUES (@infotext, @lpriority, @date_ini, @date_end,
@active, @namefile, @fkgroup, @deleted, @username);
COMMIT TRAN
SET @idinfo = SCOPE_IDENTITY();
SET NOCOUNT OFF;
IF @log = 1
BEGIN
DECLARE @RC INT
DECLARE @idlog INT
EXECUTE @RC = [dbo].[USp_TB_LOG_Insert]
@idlog OUTPUT, 'INSERT', @user, 'TB_INFO', @idinfo
END
带有参数的una command.adodb返回错误:
将数据类型varchar转换为int时出错
编号:-2147217913
和我的子例程(新):
Public Sub SaveInfoOPE()
Dim cmInsertInfo As ADODB.Command
Dim iReturnValue As Integer
' create a ADO command for StoredProcedure [dbo].[USp_TB_INFO_Insert]
If ValidateDataOpe() Then
On Error GoTo errcommand
Set cmInsertInfo = New ADODB.Command
Set cmInsertInfo.ActiveConnection = mcn ' is = "DSN=INFOPOINT"
With cmInsertInfo
.CommandType = adCmdStoredProc
.CommandText = "dbo.USp_TB_INFO_Insert"
.Parameters.Append .CreateParameter("@infotext", adVarChar, adParamInput, Len(infotext))
.Parameters("@infotext").Value = infotext 'present value='Printer out'
.Parameters.Append .CreateParameter("@lpriority", adInteger, adParamInput)
.Parameters("@lpriority").Value = Priority 'present value='1'
.Parameters.Append .CreateParameter("@sDate_ini", adChar, adParamInput, 20)
.Parameters("@sDate_ini").Value = Date_Ini 'present value='08/03/2019 13:40:07'
'******** not for OPE *****
'If Not Date_End = "" Then
' .Parameters.Append .CreateParameter("@sDate_end", adChar, adParamInput, 20)
' .Parameters("@sDate_end").Value = Date_End
'End If
'*************************************
If Not Len(namefile & "") = 0 Then
.Parameters.Append .CreateParameter("@namefile", adVarChar, adParamInput, Len(namefile))
.Parameters("@namefile").Value = namefile 'present value=""
End If
.Parameters.Append .CreateParameter("@username", adVarChar, adParamInput, Len(UserName))
.Parameters("@username").Value = UserName 'present value='alip'
.Parameters.Append .CreateParameter("@user", adVarChar, adParamInput, Len(User))
.Parameters("@user").Value = User 'present value='AL'
.Parameters.Append .CreateParameter("@fkgroup", adInteger, adParamInput)
.Parameters("@fkgroup").Value = FkGroup 'present value='1'
.Parameters.Append .CreateParameter("@active", adInteger, adParamInput)
.Parameters("@active").Value = IIf(Active, 1, 0) 'present active value='True'
.Parameters.Append .CreateParameter("@log", adInteger, adParamInput)
.Parameters("@log").Value = IIf(Log, 1, 0) 'present log value='true'
.Parameters.Append .CreateParameter(, adInteger, adParamReturnValue, , Null)
On Error GoTo errcmexecute
.Execute
iReturnValue = .Parameters(0)
End With
RaiseEvent DatInsert(True, "")
End If
'************ close command
exitcommand:
Set cmInsertInfo = Nothing
Exit Sub
errcommand:
MsgBox "error: " & err.Description & vbCrLf _
& "number: " & err.Number, vbCritical + vbOKOnly, "Procedure Command Save"
RaiseEvent DatInsert(False, "")
GoTo exitcommand
errcmexecute:
MsgBox "error: " & err.Description & vbCrLf _
& "number: " & err.Number, vbCritical + vbOKOnly, "Procedure Command Save"
RaiseEvent DatInsert(False, "")
GoTo exitcommand
End Sub
command.adodb.execute
返回错误:
将数据类型varchar转换为int时出错。
编号:-2147217913
请帮助我
感谢所有人