VS中的SQl异常

发布于 2024-12-06 23:21:07 字数 1074 浏览 5 评论 0原文

我在 VS 中调试时遇到 SQLException。 错误是: 传入的表格数据流 (TDS) 远程过程调用 (RPC) 协议流不正确。参数 8(“@Pris”):提供的值不是数据类型 float 的有效实例。检查源数据是否存在无效值。无效值的一个示例是小数位数大于精度的数字类型数据。

      string query = "INSERT INTO Indkøbsliste (ListID, ListeNr, Stregkode, Navn, Antal, Pris) Values (@ListID, @ListeNr, @Stregkode, @Navn, @Antal, @Pris)" ;
      SqlCommand com = new SqlCommand(query, myCon); 
      com.Parameters.Add("@ListID",System.Data.SqlDbType.Int).Value=id; 
      com.Parameters.Add("@ListeNr",System.Data.SqlDbType.Int).Value=listnr; 
      com.Parameters.Add("@Stregkode",System.Data.SqlDbType.VarChar).Value=strege ; 
      com.Parameters.Add("@Navn",System.Data.SqlDbType.VarChar).Value=navn ; 
      com.Parameters.Add("@Antal",System.Data.SqlDbType.Int).Value=il.Antal; 
      com.Parameters.Add("@Pris",System.Data.SqlDbType.Float).Value=il.Pris; 

        com.ExecuteNonQuery();
        com.Dispose();
        myCon.Close();

我在 ExecuteNonQuery 处得到它。我知道异常是什么,但我不知道如何修复它。在我的数据库中,我在“价格”上使用浮动,在 VS 中我使用双精度。我想我读过一些东西,说 double en VS 就像 sql 中的浮点数。

谢谢!

I'm getting an SQLexception while debugging in VS.
The error is:
The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 8 ("@Pris"): The supplied value is not a valid instance of data type float. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision.

      string query = "INSERT INTO Indkøbsliste (ListID, ListeNr, Stregkode, Navn, Antal, Pris) Values (@ListID, @ListeNr, @Stregkode, @Navn, @Antal, @Pris)" ;
      SqlCommand com = new SqlCommand(query, myCon); 
      com.Parameters.Add("@ListID",System.Data.SqlDbType.Int).Value=id; 
      com.Parameters.Add("@ListeNr",System.Data.SqlDbType.Int).Value=listnr; 
      com.Parameters.Add("@Stregkode",System.Data.SqlDbType.VarChar).Value=strege ; 
      com.Parameters.Add("@Navn",System.Data.SqlDbType.VarChar).Value=navn ; 
      com.Parameters.Add("@Antal",System.Data.SqlDbType.Int).Value=il.Antal; 
      com.Parameters.Add("@Pris",System.Data.SqlDbType.Float).Value=il.Pris; 

        com.ExecuteNonQuery();
        com.Dispose();
        myCon.Close();

I'm getting it at the ExecuteNonQuery. I know what the exception is about, but i Dont know haów to fix it. In my database i'm using float on my "prices", and in VS im using double. I think that I have read something that says a double en VS are like a float in sql.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

濫情▎り 2024-12-13 23:21:07

当源超出目标参数范围时,会出现此错误。确保精度和小数位数在目标数据类型的范围内。 http://social.msdn.microsoft.com/Forums/en-US/sqldataaccess/thread/4392aad1-eed0-4d6a-b891-90685b2e8258/

This error appears when source exceeds the target parameter range. Ensure precision and scale are in range of target data type. http://social.msdn.microsoft.com/Forums/en-US/sqldataaccess/thread/4392aad1-eed0-4d6a-b891-90685b2e8258/

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