views:

219

answers:

1

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  A: 

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().

ranomore
Do you mean writing the sql statemnt to the page?I added the code above but nothing shows up.I tired adding .ContainsString but intellisense did not recognize it?
Brett
I meant checking the sql statement while running the code in your visual studio debugger. Try downloading SubSonic 2.2 and replacing the SubSonic.dll file in your project. Get it from the featured downloads here: http://code.google.com/p/subsonicproject/. That will give you the ContainsString(), StartsWith() and EndsWith() methods.
ranomore
I am pretty new to VS and not sure how to run the code in the debugger. I will get the newer version of Subsonic.
Brett
In visual Studio if hit "F5" that will run the code in a debug mode. Then all you need to do is click with your mouse just to the left of the code screen next to the line where you want the debugger to stop.
runxc1 Bret Ferrier