Intellisense states a parameter for a strongly typed DataSet query is a Decimal when it should be a String
此查询用于查询在Visual Studio数据集设计器中创建的强类型数据集:
1 2 3 4 5 6 7 8 | SELECT ID, PaymentAmount, PaymentDate, WhatWasPaymentFor FROM Payments WHERE ParentID = @ParentID AND (@PaymentDate is null OR PaymentDate = @PaymentDate) AND (@PaymentAmount is null OR PaymentAmount = @PaymentAmount) AND ((@SearchValue is null OR (WhatWasPaymentFor LIKE '%' + @SearchValue + '%' OR @SearchValue='ALL')) ) |
在VB.Net代码隐藏文件中,我们调用查询来填充数据集,如下所示:
1 | Dim tblObject = theTableAdapter.GetDataByAllInOne(dcmParentsId, Nothing, Nothing, TextBoxSearch.Text) |
当我认为它是一个字符串时,Intellisense会将第四个参数显示为十进制。当鼠标悬停在@SearchValue的参数上时,我发现了这一点。
执行此编码时,显示此错误:
1 | Conversion from string"Books" to type 'Decimal' is not valid. |
此查询中唯一为小数的列是PaymentAmount,它恰好是第三个参数而不是第四个参数。
我不确定为什么intellisense指出第4个参数@SearchValue是一个十进制。您能告诉我如何将其更改为字符串吗?
发生的一件有趣的事是,如果在SQL Server Magagement Studio中以以下方式运行查询,则该查询可以正常运行:
1 2 3 4 5 6 7 8 9 10 11 12 13 | DECLARE @SearchValue VARCHAR = 'Books' DECLARE @ParentID INT = 3 DECLARE @PaymentDate DATETIME = NULL DECLARE @PaymentAmount MONEY = NULL SELECT ID, PaymentAmount, PaymentDate, WhatWasPaymentFor FROM Payments WHERE ParentID = @ParentID AND (@PaymentDate is null OR PaymentDate = @PaymentDate) AND (@PaymentAmount is null OR PaymentAmount = @PaymentAmount) AND ((@SearchValue is null OR (WhatWasPaymentFor LIKE '%' + @SearchValue + '%' OR @SearchValue='ALL')) ) |
也许我不知道需要在DataSet设计器中进行一些设置。
在设计器中,查询将按期望的顺序显示期望的参数,即您应该看到类似GetDataByAllInOne(@ ParentID,@ PaymentDate,@ PaymentAmount,@ SearchValue)的信息。
您可以先检查一下吗?