I saw that some others faced this similar problem. I have read and checked the question titled Procedure expects parameter which was not supplied. I thought it would solve my problem but I was wrong :( I did check the steps that were advised there with no luck. Here is my code:

我看到其他一些人遇到了类似的问题。我已阅读并检查了题为“过程预期未提供的参数”的问题。我认为它可以解决我的问题,但我错了:(我确实检查了那里建议没有运气的步骤。这是我的代码:

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;

Stored Procedure is:

存储过程是:

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

While debugging, i found the value of nBillID = 1.0 and sSerialNo='B201200001'. But when trying to execute the ExecuteNonQuery command, it gives the exception:

在调试时,我发现nBillID = 1.0和sSerialNo ='B201200001'的值。但是在尝试执行ExecuteNonQuery命令时,它会给出异常:

"Procedure 'usp_PettyCash_AddBillInfo' expects parameter '@BillID', which was not supplied."

“程序'usp_PettyCash_AddBillInfo'需要参数'@BillID',这是未提供的。”

I can't find any workarounds. Please help. Sorry for re-asking the question.

我找不到任何解决方法。请帮忙。很抱歉重新提问。

As a workaround, I used this:

作为一种解决方法,我使用了这个:

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() + "')";

Although I did not like this type of coding, but this works.

虽然我不喜欢这种类型的编码,但这种方法有效。

1 个解决方案

#1


3

Try adding:

oOleDbCommand.CommandType = CommandType.StoredProcedure;

I believe without this, your parameter values are supposed to be added inline (like an inline SQL statement). E.g:

我相信没有这个,你的参数值应该是内联添加的(就像一个内联SQL语句)。例如:

oOleDbCommand.CommandText = "usp_PettyCash_AddBillInfo @BillID, @SerialNo...";

So your adding your parameters to the command, but they are not in the CommandText, so they're not being applied anywhere.

因此,您将参数添加到命令中,但它们不在CommandText中,因此它们不会在任何地方应用。

To call a stored procedure, set the CommandType of the Command object to StoredProcedure. Once the CommandType is set to StoredProcedure, you can use the Parameters collection to define parameters, as in the following example.

要调用存储过程,请将Command对象的CommandType设置为StoredProcedure。将CommandType设置为StoredProcedure后,可以使用Parameters集合来定义参数,如以下示例所示。

http://msdn.microsoft.com/en-us/library/yy6y35y8(v=vs.71).aspx

更多相关文章

  1. SQL 函数如何设置参数默认值
  2. sql语句,order by后加参数问题
  3. 检索SQL语句的输出参数
  4. android-exploitme(四):参数篡改
  5. 如何在函数中将两个参数从1个类传递给另一个?
  6. Android的startActivityForResult()与onActivityResult()与setRe
  7. Android开发入门之为应用添加多个Activity与参数传递
  8. java socket参数详解:TcpNoDelay
  9. 在spring 中如何注入map,set,list,property等参数

随机推荐

  1. 红茶一杯话Binder(传输机制篇_下)
  2. Linux(Android):如何禁用Intel DPST(显示节电
  3. 【原创】安卓程序员的大革命,Cocovr框架库
  4. Android开发中MinSDK与TargetSDK不在同一
  5. android项目 之 记事本(14) ----- 手势缩放
  6. 使用RecyclerView的AppBarLayout可以在不
  7. 更新后-崩溃com.google.android.gms:play
  8. Android 进阶:Fragment 源码深入理解
  9. 显示操作栏和向上导航 - Android
  10. Android View事件传播机制