1

在过去的一个小时里,我一直被以下错误所困扰:

“过程或函数‘write_call’需要参数‘@Date’,但未提供。”

@date参数是smalldatetime。我正在尝试传递价值#1/27/2009 04:32:00 PM#

我正在使用 SQLExpress 2014。

相同的存储过程已在 SQLExpress 2008 上投入生产

T-SQL 存储过程:

 ALTER proc [dbo].[write_call]
(
    @Date smalldatetime, @Duration smallint, @Ring tinyint, @Extension smallint = null, @Number varchar(20) = null, @LineID smallint, 
    @AccountID smallint = null, @AccountName varchar(30) = null, @UnitID smallint = null, @UnitName varchar(30) = null, @AreaName varchar(100) = null, @CallType char(1) = null,
    @CallCode varchar(6) = null, @Rate numeric(5,2) = 0.0, @Cost numeric(12,2) = 0.0, @TAC varchar(10) = null
)

as

declare @id int=0, @old_acctid int=0  --, @old_rate numeric(5,2)=0.0, @old_cost numeric(12,2)=0.0

select @id=o.ID,@old_acctid=o.AccountID from OutboundCalls o where o.Date=@Date and o.Duration=@Duration and o.Number=@Number

if @id=0
    begin
        insert into _OutboundCalls (Date, Duration, Ring, Extension, Number, LineID, AccountID, AccountName, UnitID, UnitName, AreaName, CallType,CallCode, Rate, Cost, TAC,redirected,contactid,CompanyID,CompanyName)
        values (@Date, @Duration, @Ring, @Extension, @Number, @LineID, @AccountID, @AccountName, @UnitID, @UnitName, @AreaName, @CallType, @CallCode, @Rate, @Cost, @TAC,1,0,1,'PricewaterhouseCoopers')
    end
else if @id>0 and @old_acctid<>@AccountID
    update OutboundCalls set AccountID=@AccountID, UnitID=@UnitID,AccountName=@AccountName,UnitName=@UnitName
    where OutboundCalls.ID=@id

VB.NET 2015:

Private Sub write_call(c As CallInfo)
    Using cnn = New SqlClient.SqlConnection(connString)
        Using cmd = New SqlClient.SqlCommand("write_call", cnn)

            cmd.Parameters.AddWithValue("@Date", c.dt)
            cmd.Parameters.AddWithValue("@Duration", c.secDurn)
            cmd.Parameters.AddWithValue("@Ring", 0)
            cmd.Parameters.AddWithValue("@Extension", c.src)
            cmd.Parameters.AddWithValue("@Number", c.dst)
            cmd.Parameters.AddWithValue("@LineID", c.lineId)
            cmd.Parameters.AddWithValue("@AccountID", c.account_id)
            cmd.Parameters.AddWithValue("@AccountName", c.account_name)
            cmd.Parameters.AddWithValue("@UnitID", c.unit_id)
            cmd.Parameters.AddWithValue("@UnitName", c.unit_name)
            cmd.Parameters.AddWithValue("@AreaName", c.area?.Name)
            cmd.Parameters.AddWithValue("@CallType", c.dst_type)
            cmd.Parameters.AddWithValue("@CallCode", c.callcode)
            cmd.Parameters.AddWithValue("@Rate", c.rate?.rate)
            cmd.Parameters.AddWithValue("@Cost", c.Cost)
            cmd.Parameters.AddWithValue("@TAC", c._oC)

            cnn.Open()

            Try
                cmd.ExecuteNonQuery()
            Catch ex As Exception
                Stop
            End Try
        End Using
    End Using
End Sub
4

1 回答 1

1

您的代码似乎没有设置CommandType属性。此属性默认为CommandType.Text,当您将 sql 字符串作为CommandText.

如果传递存储过程的名称,则需要设置

cmd.CommandType = CommandType.StoredProcedure

没有这个设置,SqlCommand 的行为是不可预测的。

于 2015-10-08T18:37:52.557 回答