ASP.NET 搜索多个参数 [英] ASP.NET Search on multiple parameters
问题描述
我正在尝试在 gridview 上显示搜索结果.我希望搜索显示姓氏和名字的结果.我正在将 ASP.NET 与 Subsonic 一起使用,但不知道如何修改下面的语句.我猜它在某处需要通配符?
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();
推荐答案
我认为这应该可行.
您是否熟悉从该查询中获取生成的 SQL?
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();
检查 sql 的值(在该行有一个断点)以提供问题的进一步线索.
Check the value of sql (with a breakpoint on that line) to provide further clues into the problem.
对于通配符 - 使用 ContainsString() 方法而不是像这样硬编码通配符:
For the wildcard - use the ContainsString() method instead of hardcoding a wildcard like so:
.Where(PastAwardName.Columns.LName).ContainsString(this.txtSearchName.Text)
这会自动将提供者特定的通配符添加到参数的开头和结尾.你也可以做 StartsWith() 和 EndsWith().
This will automatically add the provider-specific wildcard character to the beginning and end of the parameter. You can also do StartsWith() and EndsWith().
这篇关于ASP.NET 搜索多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!