调试 vb.net SQL 命令
我正在尝试调用执行 INSERT 的 SQL 存储过程。然而,当我浏览我的 vb.net 代码时,我收到一条消息:“过程或函数 sp_InsertARPlanner 指定了太多参数。”
我已经仔细检查过,但 VB 中的 SQL 字符串具有相同的 #参数的数量与存储过程中相同。
我有什么想法可以调试这个吗?
更新
SQLCmd.CommandText = "sp_InsertARPlanner"
SQLCmd.CommandType = CommandType.StoredProcedure
SQLCmd.Parameters.AddWithValue("@Origin", Trim(txtOrigin.Text))
SQLCmd.Parameters.AddWithValue("@Destination", Trim(txtDest.Text))
SQLCmd.Parameters.AddWithValue("@Miles", iMiles)
SQLCmd.Parameters.AddWithValue("@Rate", iAvgRateperMile)
SQLCmd.Parameters.AddWithValue("@MinCost", dMinCost)
SQLCmd.Parameters.AddWithValue("@Zone", sZone)
SQLCmd.Parameters.AddWithValue("@LaneHaulCost", dLaneHaulCost)
SQLCmd.Parameters.AddWithValue("@TotalCost", dTotalCost)
SQLCmd.Parameters.AddWithValue("@TotalWithSurch", dTotalWithSurch)
SQLCmd.Parameters.AddWithValue("@AvgTypeRate", sAvgTypeRate)
SQLCmd.Parameters.AddWithValue("@AvgLoads", sAvgLoads)
SQLCmd.Parameters.AddWithValue("@FuelLevel", dFuelPercent)
SQLCmd.Parameters.AddWithValue("@Fuel", dFuelAmount)
SQLCmd.Parameters.AddWithValue("@AverageRateAmount", dAverageRateAmount)
SQLCmd.Parameters.AddWithValue("@Floor", decFloor)
SQLCmd.Parameters.AddWithValue("@RainBulkRate", decBulkRate)
SQLCmd.Parameters.AddWithValue("@RateComments", txtRateDesc..Text)
SQLCmd.Parameters.AddWithValue("@PremiumField", txtPremium.Text)
SQLCmd.Parameters.AddWithValue("@EquipCategory", Trim(cboEquipType.Text))
SQLCmd.Parameters.AddWithValue("@UpdateDate", DateTime.Now)
SQLCmd.Parameters.AddWithValue("@FreightDesc", "txtFreightDesc.Text")
Try
SQLCmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
SQLCon.Close()
SQLCmd.Parameters.Clear()
Exit Sub
End Try
ALTER PROCEDURE [dbo].[sp_InsertARPlanner]
(@Origin nvarchar(150)
,@Destination nvarchar(150)
,@Miles nvarchar(50)
,@Rate nvarchar(5)
,@MinCost decimal(5,2)
,@Zone varchar(3)
,@LaneHaulCost decimal(5, 2)
,@TotalCost decimal(5, 2)
,@TotalWithSurch decimal(5, 2)
,@AvgTypeRate varchar(50)
,@AvgLoads varchar(4)
,@FuelPercent decimal(5,2)
,@FuelAmount decimal(5,2)
,@AverageRateAmount decimal(5,2)
,@Floor decimal(5, 2)
,@RainBulkRate decimal(5, 2)
,@RateComments nvarchar(50)
,@PremiumField nvarchar(50)
,@EquipCategory nvarchar(50)
,@UpdateDate datetime
,@FreightDesc nvarchar(50))
I am attempting to call SQL stored procedure that does an INSERT. However, when I walkthrough my vb.net code, I get a message saying "Procedure or function sp_InsertARPlanner has too many arguments specified."
I have double checked, but the SQL string in VB has the same # of params as in the stored procedure.
Any ideas how I can debug this?
Update
SQLCmd.CommandText = "sp_InsertARPlanner"
SQLCmd.CommandType = CommandType.StoredProcedure
SQLCmd.Parameters.AddWithValue("@Origin", Trim(txtOrigin.Text))
SQLCmd.Parameters.AddWithValue("@Destination", Trim(txtDest.Text))
SQLCmd.Parameters.AddWithValue("@Miles", iMiles)
SQLCmd.Parameters.AddWithValue("@Rate", iAvgRateperMile)
SQLCmd.Parameters.AddWithValue("@MinCost", dMinCost)
SQLCmd.Parameters.AddWithValue("@Zone", sZone)
SQLCmd.Parameters.AddWithValue("@LaneHaulCost", dLaneHaulCost)
SQLCmd.Parameters.AddWithValue("@TotalCost", dTotalCost)
SQLCmd.Parameters.AddWithValue("@TotalWithSurch", dTotalWithSurch)
SQLCmd.Parameters.AddWithValue("@AvgTypeRate", sAvgTypeRate)
SQLCmd.Parameters.AddWithValue("@AvgLoads", sAvgLoads)
SQLCmd.Parameters.AddWithValue("@FuelLevel", dFuelPercent)
SQLCmd.Parameters.AddWithValue("@Fuel", dFuelAmount)
SQLCmd.Parameters.AddWithValue("@AverageRateAmount", dAverageRateAmount)
SQLCmd.Parameters.AddWithValue("@Floor", decFloor)
SQLCmd.Parameters.AddWithValue("@RainBulkRate", decBulkRate)
SQLCmd.Parameters.AddWithValue("@RateComments", txtRateDesc..Text)
SQLCmd.Parameters.AddWithValue("@PremiumField", txtPremium.Text)
SQLCmd.Parameters.AddWithValue("@EquipCategory", Trim(cboEquipType.Text))
SQLCmd.Parameters.AddWithValue("@UpdateDate", DateTime.Now)
SQLCmd.Parameters.AddWithValue("@FreightDesc", "txtFreightDesc.Text")
Try
SQLCmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
SQLCon.Close()
SQLCmd.Parameters.Clear()
Exit Sub
End Try
ALTER PROCEDURE [dbo].[sp_InsertARPlanner]
(@Origin nvarchar(150)
,@Destination nvarchar(150)
,@Miles nvarchar(50)
,@Rate nvarchar(5)
,@MinCost decimal(5,2)
,@Zone varchar(3)
,@LaneHaulCost decimal(5, 2)
,@TotalCost decimal(5, 2)
,@TotalWithSurch decimal(5, 2)
,@AvgTypeRate varchar(50)
,@AvgLoads varchar(4)
,@FuelPercent decimal(5,2)
,@FuelAmount decimal(5,2)
,@AverageRateAmount decimal(5,2)
,@Floor decimal(5, 2)
,@RainBulkRate decimal(5, 2)
,@RateComments nvarchar(50)
,@PremiumField nvarchar(50)
,@EquipCategory nvarchar(50)
,@UpdateDate datetime
,@FreightDesc nvarchar(50))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
sp_
开头,它代表 sql server 中的系统过程,并且会导致 sql server 做额外的工作来寻找您的过程(但这不是您的问题) ,但这是一个很好的做法)。Try this:
sp_
That stands for system procedure in sql server, and will cause sql server to do extra work looking for your procedure (this isn't your problem though, but it's good practice).单步执行代码时,可能会在某个点填充存储过程及其参数,可能是在 SqlCommand 对象中。您可以在断点处捕获该存储过程调用。然后,将其复制到查询工具,调用 EXEC 并将 sproc 调用粘贴进去。然后运行它。这样,您将执行代码发送的确切存储过程调用。
如果您提供代码的更多详细信息,我们可以更具体地说明如何捕获存储过程调用。
When stepping through your code, there will be a point where the stored procedure and its parameters have been populated, perhaps in a SqlCommand object. You can capture that sproc call at a breakpoint. Then, copy it to your query tool, call EXEC and paste the sproc call in. Then run it. That way, you will be executing the exact stored procedure call that your code is sending.
If you provide more details of your code, we can be more specific on exactly how to capture the sproc call.