ASP.NET Search on multiple parameters

北慕城南 提交于 2019-12-11 18:11:41

问题


I am trying to display the results of a search on a gridview. I want the search to show the results for both last and first name. I am using ASP.NET with Subsonic and can't figure out how to modify the statemnt below. I am guessing it needs a wildcard somewhere?

Name: <asp:TextBox ID="txtSearchName" runat="server"></asp:TextBox> 

    GridView1.DataSource = new Select(PastAwardName.Schema.TableName + ".*", PastAwardType.Schema.TableName + ".*")
          .From(PastAwardName.Schema)
          .InnerJoin(PastAwardType.Schema.TableName, PastAwardType.Columns.VolID, PastAwardName.Schema.TableName, PastAwardName.Columns.VolID)
          .Where(PastAwardName.Columns.LName).IsEqualTo(this.txtSearchName.Text)
          .Or(PastAwardName.Columns.FName).IsEqualTo(this.txtSearchName.Text)
          .OrderAsc(PastAwardType.Columns.AwardYear)
          .ExecuteDataSet();

回答1:


I think that should work.

Are you familiar with getting the generated SQL from that query?

SubSonic.SqlQuery q = new Select(PastAwardName.Schema.TableName + ".*", PastAwardType.Schema.TableName + ".*")
          .From(PastAwardName.Schema)
          .InnerJoin(PastAwardType.Schema.TableName, PastAwardType.Columns.VolID, PastAwardName.Schema.TableName, PastAwardName.Columns.VolID)
          .Where(PastAwardName.Columns.LName).IsEqualTo(this.txtSearchName.Text)
          .Or(PastAwardName.Columns.FName).IsEqualTo(this.txtSearchName.Text)
          .OrderAsc(PastAwardType.Columns.AwardYear);
string sql = q.BuildSqlStatement();

Check the value of sql (with a breakpoint on that line) to provide further clues into the problem.

For the wildcard - use the ContainsString() method instead of hardcoding a wildcard like so:

.Where(PastAwardName.Columns.LName).ContainsString(this.txtSearchName.Text)

This will automatically add the provider-specific wildcard character to the beginning and end of the parameter. You can also do StartsWith() and EndsWith().



来源:https://stackoverflow.com/questions/799953/asp-net-search-on-multiple-parameters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!