“参数?_1没有默认值"; ExecuteReader时出错 [英] "Parameter ?_1 has no default value" error when ExecuteReader
问题描述
Web服务中的以下代码有问题.寻找了解决方案,但是我所看到的似乎与我在下面所做的没什么不同.
Having problem with the code below in a web service. Have searched for a solution but nothing that I have seen seems different to what I am doing below.
注意:字符串变量'AccountNo'已传递到包含以下代码的函数中.
该错误在代码的最后一行ExecuteReader上生成.
The error is generated on the last line of code - ExecuteReader.
Dim sConnString As String
Dim rdr As OleDbDataReader
Dim orderPaid As Decimal
Dim fbeused As Decimal
sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\orders.mdb'"
Dim conn As New OleDbConnection(sConnString)
Dim sb As New StringBuilder
sb.Append("SELECT DISTINCTROW OrderHeaders.Accountno, Sum(([paidqty]*[unitprice])*[orderheaders].[entpercent]/100) AS orderpaid, Sum([freeqty]*[unitprice]) AS fbeused")
sb.Append(" FROM OrderHeaders INNER JOIN OrderDetails ON OrderHeaders.[OrderNo] = OrderDetails.[OrderNo]")
sb.Append(" GROUP BY OrderHeaders.Accountno HAVING OrderHeaders.Accountno=?")
Dim sqlString As String = sb.ToString
Dim cmd As New OleDbCommand(sqlString, conn)
cmd.CommandType = CommandType.Text
'cmd.Parameters.AddWithValue("AccNo", AccountNo)
cmd.Parameters.Add("AccNo", OleDbType.VarWChar).Value = AccountNo
conn.Open()
rdr = cmd.ExecuteReader()
我得到的错误是(如上所述)
The error I get is (as mentioned above)
Parameter ?_1 has no default value
推荐答案
问题实际上是错误的假设,那就是代码中有错误.
The question in fact had a wrong assumption and that was that there was an error in the code.
SQL查询的语法正确,并且已正确插入参数.但是,测试数据包含错误,因此正确格式的查询不会返回任何结果.
The syntax of the SQL query was correct and the parameter was being inserted correctly. However the test data contained errors and therefore no result was being returned by a correctly formatted query.
非常感谢您的输入.
这篇关于“参数?_1没有默认值"; ExecuteReader时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!