我有以下存储过程,我从我的 Windows 窗体应用程序数据集中调用它,如下所示:
Me.TransactionTableAdapter.spPaymentApply(130, iAmount, Now)
尽管我提供了 CustomerID,(并单步执行代码以查看它是否确实存在 - 确实存在)但在执行过程中出现以下错误:过程或函数“PaymentApply”需要参数“@CustomerID”,但未提供该参数。
这是我的SP:
USE [dbPB]
GO
/****** Object: StoredProcedure [dbo].[PaymentApply] Script Date: 05/30/2013 18:34:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[PaymentApply]
@CustomerID int,
@Amount int,
@AsOfDate datetime
AS
WITH Totals AS (
SELECT
T.*,
RunningTotal =
Coalesce (
(SELECT Sum(S.Buyin - Coalesce(S.CreditPaid, 0))
FROM [Transaction] S
WHERE
T.CustomerID = S.CustomerID
AND S.Type = 'Credit'
AND S.Buyin > Coalesce(T.CreditPaid, 0)
AND (
T.Starttime > S.Starttime
OR (
T.Starttime = S.Starttime
AND T.TransactionID > S.TransactionID
)
)
),
0)
FROM
[Transaction] T
WHERE
CustomerID = @CustomerID
AND T.Type = 'Credit'
AND T.Buyin > Coalesce(T.CreditPaid, 0)
)
UPDATE T
SET
T.EndTime = P.EndTime,
T.CreditPaid = Coalesce(T.CreditPaid, 0) + P.CreditPaid
FROM
Totals T
CROSS APPLY (
SELECT TOP 1
V.*
FROM
(VALUES
(T.Buyin - Coalesce(T.CreditPaid, 0), @AsOfDate),
(@Amount - RunningTotal, NULL)
) V (CreditPaid, EndTime)
ORDER BY
V.CreditPaid,
V.EndTime DESC
) P
WHERE
T.RunningTotal <= @Amount
AND @Amount > 0;
;
VB代码:
Private Sub btnTransProcess_Click(sender As Object, e As EventArgs) Handles btnTransProcess.Click
Dim iAmount As Integer
Dim drv As DataRowView = CType(Me.cboCustomerName.SelectedItem, DataRowView)
Dim SelCustId As Integer
SelCustId = drv.Item("CustomerID")
Try
iAmount = CType(txtCreditPayment.Text, Integer)
Catch ex As Exception
MessageBox.Show("Enter a valid Credit Payment Amount!", "Invalid Amount", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
MsgBox(SelCustId)
Me.TransactionTableAdapter.spPaymentApply(130, iAmount, Now)
'
'Dim command As New SqlCommand(queryString, connection)
'command.Parameters.AddWithValue("@CustomerID", 123)
End Sub