このトピックはすべてここにありますが、私はINSERT
,UPDATE
,ではありません。私の声明は平易でシンプルなSELECT
の声明です。これまでのところ、私は1つになるまでデータベース内の116の異なる項目を扱ってきました。サブクエリが1つ以上の値を返しました
私は検索エンジンを持っており、私たちのデータベースにあるすべての単一の製品を情報に追加しています。これはすべてWebサイトで行われますが、ProductID 331を検索してクリックすると、エラーページに移動します。Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
これでエラーが発生するのは私には間違いありません1つの製品。 これは私が使用している声明です。なぜ誰が1つの製品がこのエラーの原因になるのか知っていますか?
のWebService:
Public Class ProductSearch
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetProducts(ByVal prefixText As String, ByVal count As Integer)
As String()
Dim ProductSql As String = "Select DISTINCT ProductID, ProductName
FROM Product WHERE ProductName
LIKE '%' & @prefixText & '%'
ORDER BY ProductName ASC"
Using sqlConn As New SqlConnection
(System.Configuration.ConfigurationManager.ConnectionStrings
("LocalSqlServer").ConnectionString)
sqlConn.Open()
Dim myCommand As New SqlCommand(ProductSql, sqlConn)
myCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50)
.Value = prefixText
Dim myReader As SqlDataReader = myCommand.ExecuteReader()
Dim myTable As New DataTable
myTable.TableName = "ProductSearch"
myTable.Load(myReader)
sqlConn.Close()
Dim items As String() = New String(myTable.Rows.Count - 1) {}
Dim i As Integer = 0
For Each dr As DataRow In myTable.Rows
Dim id As String = dr("ProductID").ToString()
Dim name As String = dr("ProductName").ToString()
Dim item As String = AjaxControlToolkit.AutoCompleteExtender
.CreateAutoCompleteItem(name, id)
items.SetValue(item, i)
i += 1
Next
Return items
End Using
End Function
End Class
Webサービスを呼び出すaspxページ:
<%@ Page Title="Product Search" Language="VB" MasterPageFile="~/MasterPage.master"
AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit"
TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript">
function AutoCompleteClientMethod(source, eventArgs) {
var value = eventArgs.get_value();
window.location = ("/Product/Default.aspx?id=" + value)
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="ProductSearch.asmx" />
</Services>
</asp:ScriptManager>
<asp:TextBox ID="Search" runat="server" AutoComplete="off"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
TargetControlID="Search" ServicePath="~/ProductSearch.asmx"
ServiceMethod="GetProducts" MinimumPrefixLength="1" CompletionSetCount="120"
EnableCaching="true" OnClientItemSelected="AutoCompleteClientMethod">
</asp:AutoCompleteExtender>
</div><!--End of main div -->
</asp:Content>
UPDATE:2011年11月9日 - 私はこの問題を持っているカップルより多くのレコードを発見しました。これらはProductID 331-335です。私はここで何が起こっているのか分かりません。これらの製品が実際には存在しないか、何らかのバグがある可能性がありますか? DISTINCTつの結果を意味するものではありません、私は、これはサブselectクエリであると仮定し
122 'Managed account section of the Web Site'
331 'Elliott Wave Principle Key to Market Behavior'
332 'Targeting Profitable Entry & Exit Points'
333 'Essentials of Trading It's not WHAT You Think, It's HOW You Think'
334 'Exceptional Trading The Mind Game'
335 'Fibonacci Analysis'
あなたのコードからの完全な質問は確実ですか?副次的な問題:PrefixTextは、潜在的なSQLインジェクションを避けるために、バインドされた変数であり、文字列の連結ではない方が良いでしょう。 – Andrew
@Andrew私のコードを更新しました – jlg
私はこのエラーがなぜ起こっているのか疑問に思うサブクエリはありません。私が考えることができる唯一のことは、ユーザーをリダイレクトしようとしているときにjavascript関数が複数の値を取り戻しているということです。 – jlg