【问题标题】:ControlParameter - Syntax error: Missing operand after 'Where' operatorControlParameter - 语法错误:“Where”运算符后缺少操作数
【发布时间】:2013-11-07 12:08:02
【问题描述】:

我想按下拉值搜索。我在这种情况下使用 ControlParameters 并希望通过用户选择的下拉列表进行搜索。是否可以使用 ControlParameters?我把错误放在下面,但我得到的错误是

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">

            <p>Show all employees with the following title:</p>

            <asp:SqlDataSource id="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:mySQLConnectionString%>"
                SelectCommand="SELECT * FROM tblmovie"
                FilterExpression="MovieID='{0}' or MovieName Like '%'{1}'%' and {2} Like '%'{3}'%'">
                <FilterParameters>
                      <asp:ControlParameter Name="MovieID"  ControlId="DropDownList1" PropertyName="SelectedValue"/>
                      <asp:ControlParameter Name="MovieName" ControlId="DropDownList2" PropertyName="SelectedValue"/>                         
                      <asp:ControlParameter Name="Search" ControlId="DropDownList3" PropertyName="SelectedValue"/>         
                      <asp:ControlParameter Name="Search1" ControlId="txtSearch" PropertyName="text" Type="String"/>  
                </FilterParameters>
            </asp:SqlDataSource>

<table style="width: 650px" border="0" cellpadding="0" cellspacing="1" >
<tr>

<td style="width: 150px;">
Movie ID
 <asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True">
                    <asp:ListItem Value="888">Please Select...</asp:ListItem>            
                <asp:ListItem>1</asp:ListItem>
                <asp:ListItem>2</asp:ListItem>
                <asp:ListItem>3</asp:ListItem>
            </asp:DropDownList>
</td>
<td style="width: 150px;">
Movie Name
 <asp:DropDownList
                id="DropDownList2"
                runat="server"
                AutoPostBack="True">    
                 <asp:ListItem Value="999">Please Select...</asp:ListItem>              
                <asp:ListItem>1</asp:ListItem>
                <asp:ListItem>2</asp:ListItem>
                <asp:ListItem>3</asp:ListItem>
            </asp:DropDownList>
</td>

<td style="width: 150px;">
Search
        <asp:TextBox ID="txtSearch" runat="server" AutoPostBack="True" />
</td>
<td style="width: 150px;">
Where
<asp:DropDownList  id="DropDownList3" runat="server" AutoPostBack="True">
                <asp:ListItem>Please Select...</asp:ListItem>            
                <asp:ListItem>MovieName</asp:ListItem>          
                <asp:ListItem>MovieID</asp:ListItem>            
                <asp:ListItem>Oscars</asp:ListItem>                      
</asp:DropDownList>
</td>
</tr>
<tr><td colspan="4">
<p>
</p>
<p></p>
</td></tr>
<tr>
 <td colspan="4">
            <asp:GridView  id="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False"  Width="600px">
                <columns>                 
                    <asp:BoundField HeaderText="Movie Name" DataField="MovieName"  />
                    <asp:BoundField HeaderText="MovieID" DataField="MovieID" />
                    <asp:BoundField HeaderText="Release Date" DataField="ReleaseDate" />
                     <asp:BoundField HeaderText="Oscars" DataField="Oscars" />
                </columns>
            </asp:GridView>
   </td>
   </tr>     
   </table>  
 </form>
    </body>
</html>

【问题讨论】:

    标签: asp.net vb.net gridview


    【解决方案1】:
     FilterExpression="MovieID={0} or MovieName Like '%{1}%' or Oscars={2}  Where {3} Like '% txtSearch.text %'">
    

    我觉得很奇怪。

    FilterExpression="MovieID={0} or MovieName Like '%{1}%' or Oscars={2} Where {3} Like '% txtSearch.text %'">

    我不认为“哪里”这个词应该在那里?应该是“AND”还是“OR”?

    在我看来,过滤器表达式的开头似乎有一个隐含的(您不必键入的)“WHERE”。

    【讨论】:

    • 好的,所以我收到一个错误语法错误:“999”运算符后缺少操作数。我已将 {0} 的值更改为 888,所以我知道它在点 {0} 和 {1} 现在连接...
    • 您当前的代码是什么?重新发布。你想做什么?
    • 我想有效地有一个 where 语句(即在这种情况下使用 AND),其中用户选择他们要搜索的列,即名字/姓氏。我已经报告了我的代码。我看过的另一个解决方案是 SessionParameters。在我尝试将列名设为变量之前,这两种类型的代码都在工作。
    • 999 似乎来自:请选择... 这看起来像是你应该有列名的地方?如果你有 SQL 说 " 和 999 像 '%...%' 这将是一个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 2013-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多