我看到其他一些人也遇到了類似的問題。我已閱讀並檢查了標題爲Procedure expects parameter which was not supplied的問題。我認爲這將解決我的問題,但我錯了:(我做了檢查,用沒有運氣告知的步驟這裏是我的代碼:儘管提供了參數,但程序期望參數
oOleDbCommand.CommandText = "usp_PettyCash_AddBillInfo";
oOleDbCommand.Parameters.Add("@BillID", OleDbType.BigInt).Value = nBillID;
oOleDbCommand.Parameters.Add("@SerialNo", OleDbType.VarChar).Value = sSerialNo;
oOleDbCommand.Parameters.Add("@UniqueID", OleDbType.VarChar).Value = oInputBill[0].UniqueID.ToString();
oOleDbCommand.Parameters.Add("@BilledWeekDate", OleDbType.Date).Value = oInputBill[0].BilledWeekDate;
oOleDbCommand.Parameters.Add("@BilledWeekNo", OleDbType.VarChar).Value = oInputBill[0].BilledWeekNo.ToString();
oOleDbCommand.Parameters.Add("@SettledWeekDate", OleDbType.Date).Value = oInputBill[0].SettledWeekDate;
oOleDbCommand.Parameters.Add("@SettledWeekNo", OleDbType.VarChar).Value = oInputBill[0].SettledWeekNo;
oOleDbCommand.Parameters.Add("@BillStatus", OleDbType.VarChar).Value = oInputBill[0].BillStatus.ToString();
oOleDbCommand.Parameters.Add("@UpdatedBy", OleDbType.VarChar).Value = oInputBill[0].UpdatedBy;
oOleDbCommand.Parameters.Add("@UpdateDate", OleDbType.Date).Value = oInputBill[0].UpdateDate;
存儲過程:
CREATE PROCEDURE usp_PettyCash_AddBillInfo
(
@BillID bigint,
@SerialNo varchar(50),
@UniqueID varchar(50),
@BilledWeekDate datetime,
@BilledWeekNo varchar(50),
@SettledWeekDate datetime,
@SettledWeekNo varchar(50),
@BillStatus varchar(50),
@UpdatedBy varchar(50),
@UpdateDate datetime
)
AS
BEGIN
INSERT INTO t_BillInfo (BillID, SerialNo, UniqueID, BilledWeekDate, BilledWeekNo, SettledWeekDate, SettledWeekNo, BillStatus, UpdatedBy, UpdateDate)
VALUES (@BillID, @SerialNo, @UniqueID, @BilledWeekDate, @BilledWeekNo, @SettledWeekDate, @SettledWeekNo, @BillStatus, @UpdatedBy, @UpdateDate)
END
GO
雖然調試時,我發現nBillID = 1.0
和sSerialNo='B201200001'
價值,但試圖執行ExecuteNonQuery
命令時,它給人的例外:
「程序‘usp_PettyCash_AddBillInfo’預計看齊ameter'@BillID', 未提供。「
我找不到任何解決方法。請幫忙。對不起重新提問。
作爲一種變通方法,我用這個:
oOleDbCommand.CommandText = "INSERT INTO t_BillInfo (BillID, SerialNo, UniqueID, BilledWeekDate, BilledWeekNo, SettledWeekDate, SettledWeekNo, BillStatus, UpdatedBy, UpdateDate)"+
" VALUES (" + nBillID + ", '" + sSerialNo + "', '" + oInputBill[0].UniqueID.ToString() + "','" + oInputBill[0].BilledWeekDate.ToShortDateString() + "', '" + oInputBill[0].BilledWeekNo + "', '" + oInputBill[0].SettledWeekDate.ToShortDateString() + "', '" + oInputBill[0].SettledWeekNo + "', '" + oInputBill[0].BillStatus.ToString() + "', '" + oInputBill[0].UpdatedBy + "', '" + oInputBill[0].UpdateDate.ToShortDateString() + "')";
雖然我不喜歡這種類型的編碼,但這個工程。
好一件事跳到我的眼睛!你定義的參數類型'OleDbType.VarChar' - 但你沒有定義任何** **長這意味着這些參數會是** 1個字符長** - 可能**不**你想要什麼.....你需要**指定所需的長度**像這樣:'oOleDbCommand.Parameters.Add(「@ SerialNo」,OleDbType .VarChar,50).Value = .....' – 2012-02-23 09:28:46
所以我假設你已經嘗試添加'oOleDbCommand.CommandType = CommandType.StoredProcedure;',是否正確? – 2012-02-23 09:34:31
@ Enrico,是的。 @ marc_s,我也試過,但沒有變化:( – 2012-02-23 10:14:36