调试 vb.net SQL 命令

发布于 2024-10-04 12:27:38 字数 2647 浏览 1 评论 0原文

我正在尝试调用执行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放赐 2024-10-11 12:27:38

试试这个:

  1. 不要以 sp_ 开头,它代表 sql server 中的系统过程,并且会导致 sql server 做额外的工作来寻找您的过程(但这不是您的问题) ,但这是一个很好的做法)。
  2. 获取程序创建的过程字符串并将其粘贴到 sql server management studio 窗口中,以确保它在那里工作。如果不是那么你就知道问题出在哪里了。
  3. 如果是这样,请确保您正在访问您认为的数据库。如果您有多个环境,则您正在访问的数据库可能不是具有正确数量参数的数据库。

Try this:

  1. Don't start your stored procedure name with 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).
  2. Take the procedure string that the program has created and paste it into the sql server management studio window, to make sure that it works there. If not then you know where the issue is.
  3. If so, make sure you are hitting the db you think your are. If you have multiple environments it maybe that the database you are hitting isn't the one that has the correct number of parameters.
給妳壹絲溫柔 2024-10-11 12:27:38

单步执行代码时,可能会在某个点填充存储过程及其参数,可能是在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文