vba访问storedProcedure

时间:2017-08-14 06:23:03

标签: sql-server vba ms-access

我需要将数据插入ms-sql数据库,我正在使用存储过程。

这是我的storedProcedure

CREATE PROCEDURE [dbo].[AddHeatPrac] 
    -- Add the parameters for the stored procedure here
    @HeatNumber varchar(50),
    @RequestID varchar(50),
    @BlendID varchar(50),
    @TrayID1 varchar(50),
    @TrayID2 varchar(50),
    @TrayLoad1 varchar(50),
    @TrayLoad2 varchar(50),
    @TCA varchar(50),
    @NumofTray varchar(50),
    @DischargeRate varchar(50),
    @FurnaceID varchar(50),
    @TProfile varchar(50),
    @TSuction varchar(50),
    @TFlow varchar(50),
    @GasType varchar(50),
    @SS varchar(50),
    @Remark varchar(200)


AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here

    INSERT INTO [dbo].[Heat] VALUES (@HeatNumber, @RequestID, @BlendID, @TrayID1, @TrayID2, @TrayLoad1, @TrayLoad2,@TCA, @NumofTray,@DischargeRate,@FurnaceID, @TProfile, @TSuction,@TFlow, @GasType, @SS, @Remark) 



END

GO

此数据移至另一个名为[dbo]的表。[热] 表的信息是这样的。

USE [RTC_LaplaceD_DEV]
GO

/****** Object:  Table [dbo].[Heat]    Script Date: 2017-08-14 오후 3:17:19 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Heat](
    [HeatNumber] [varchar](50) NULL,
    [RequestID] [varchar](50) NULL,
    [BlendID] [varchar](50) NULL,
    [TrayID1] [varchar](50) NULL,
    [TrayID2] [varchar](50) NULL,
    [TrayLoad1] [varchar](50) NULL,
    [TrayLoad2] [varchar](50) NULL,
    [TCA] [varchar](50) NULL,
    [NumofTray] [varchar](50) NULL,
    [DischargeRate] [varchar](50) NULL,
    [FurnaceID] [varchar](50) NULL,
    [TProfile] [varchar](50) NULL,
    [TSuction] [varchar](50) NULL,
    [TFlow] [varchar](50) NULL,
    [GasType] [varchar](50) NULL,
    [SS] [varchar](50) NULL,
    [Remark] [varchar](50) NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

这是我的访问代码。

'------------------------------------Connection Setting
Dim cmd As ADODB.Command
Dim conn As ADODB.Connection
Dim strConn As String

Dim par As ADODB.Parameter           'input
'Dim introw As Integer

'introw = ListBlend.ListIndex + 1

strConn = "DRIVER=SQL Server;SERVER=CHU-AS-0004;DATABASE=RTC_LaplaceD_DEV;Trusted_Connection=Yes;"

Set conn = New ADODB.Connection
conn.Open strConn               'open connection

'------------------------------------Connection Setting
    Set cmd = New ADODB.Command
    cmd.CommandText = "dbo.AddHeatPrac"
    cmd.CommandType = adCmdStoredProc
    cmd.ActiveConnection = conn

    Set par = cmd.CreateParameter("@HeatNumber", adVarChar, adParamInput, 50, TextRequestNo.value)
    cmd.parameters.Append par
    Set par = cmd.CreateParameter("@RequestID", adVarChar, adParamInput, 50, TextRequestNo.value)
    cmd.parameters.Append par
    MsgBox ("TextRequestNo" & TextRequestNo.value)
    Set par = cmd.CreateParameter("@BlendID", adVarChar, adParamInput, 50, TextH10.value)
    cmd.parameters.Append par
    MsgBox ("BlendID" & TextH10.value)
    Set par = cmd.CreateParameter("@FurnaceID", adVarChar, adParamInput, 50, TextH13.value)
    cmd.parameters.Append par
    MsgBox ("FurnaceID" & TextH13.value)



    If TextH13.value = "RK1" Or TextH13.value = "RK2" Then
        Set par = cmd.CreateParameter("@TCA", adVarChar, adParamInput, 50, TCA.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@DischargeRate", adVarChar, adParamInput, 50, DischargeRate.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@TProfile", adVarChar, adParamInput, 50, TextH14.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@TFlow", adVarChar, adParamInput, 50, TextH16.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@TSuction", adVarChar, adParamInput, 50, TextH15.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@GasType", adVarChar, adParamInput, 50, TextH17.value)
        cmd.parameters.Append par
       Set par = cmd.CreateParameter("@SS", adVarChar, adParamInput, 50, TextH111.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@Remark", adVarChar, adParamInput, 50, TextH18.value)
        cmd.parameters.Append par

        cmd.Execute
        conn.Close 'close connection
        Set conn = Nothing
        Set cmd = Nothing

        MsgBox "Succeeded"
        List617.Requery
    ElseIf TextH13.value = "HP1" Or TextH13.value = "HP2" Or TextH13.value = "HP3" Or TextH13.value = "MP" Then
        Set par = cmd.CreateParameter("@TrayID1", adVarChar, adParamInput, 50, TextH11.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@TrayLoad1", adVarChar, adParamInput, 50, TextH12.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@TrayID2", adVarChar, adParamInput, 50, TextH110.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@TrayLoad2", adVarChar, adParamInput, 50, TextH19.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@NumofTrays", adVarChar, adParamInput, 50, TextH112.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@TProfile", adVarChar, adParamInput, 50, TextH14.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@TFlow", adVarChar, adParamInput, 50, TextH16.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@TSuction", adVarChar, adParamInput, 50, TextH15.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@GasType", adVarChar, adParamInput, 50, TextH17.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@SS", adVarChar, adParamInput, 50, TextH111.value)
        cmd.parameters.Append par
        Set par = cmd.CreateParameter("@Remark", adVarChar, adParamInput, 50, TextH18.value)
        cmd.parameters.Append par
        cmd.Execute
        conn.Close 'close connection
        Set conn = Nothing
        Set cmd = Nothing

        MsgBox "Succeeded"
        List617.Requery
    Else
    End If

我认为应该没有问题,但是当我执行我的代码时,我得到错误,说'过程或函数'AddHeatPrac'需要参数'@ Thuction',这是未提供的。检查完此错误后,我已经仔细检查了我的表设置和代码。我认为应该没有问题,但我陷入了这个错误。

请你帮我解决这个错误吗? 任何评论都会有很大帮助:))

0 个答案:

没有答案