1

所以我在 sql 2008 服务器上有一个 Customers 表,我将它绑定到我的应用程序中的 gridview。搜索按钮使用以下代码重新绑定表:

ControlParameter ctrlParam = new ControlParameter();
ctrlParam.ControlID = "SearchTextBox";
ctrlParam.PropertyName = "Text";
ctrlParam.Name = "Search";
QueryStringParameter ctrlParam2 = new QueryStringParameter();
ctrlParam2.DefaultValue = "Canceled";
ctrlParam2.QueryStringField = "Canceled";

ctrlParam2.Name = "CustomerStatus";
ctrlParam2.Type = TypeCode.String;
SqlDataSource1.SelectParameters.Clear();
SqlDataSource1.SelectParameters.Add(ctrlParam);
SqlDataSource1.SelectParameters.Add(ctrlParam2);
SqlDataSource1.SelectCommand = "SELECT FullText_for_Customers.RANK, [CustomerId], [CustomerStatus], [CustomerGroup], [CustomerFirstName], [CustomerLastName], [CustomerFullName], [CompanyName], [CustomerAddress], [CustomerCity], [CustomerState], [CustomerZipcode], [CustomerFullAddress], [CustomerEmail], [CustomerEmail2], [CustomerPhoneNumber], [CustomerPhoneNumberExt], [CustomerType], [CustomerSubscriptionType], [CustomerCost], [CustomerPaymentMethod], [CustomerPickUpDay], [CustomerPickUpDay2], [CustomerSignUpDate], [CustomerNotes], [CustomerDriver] FROM [Customers] INNER JOIN FREETEXTTABLE(Customers, (CustomerFirstName, CustomerLastName, CustomerFullName, CompanyName, CustomerAddress, CustomerCity, CustomerState, CustomerZipcode, CustomerFullAddress, CustomerEmail, CustomerEmail2, CustomerPhoneNumber, CustomerNotes), @Search) as FullText_for_Customers ON FullText_for_Customers.[KEY]=Customers.CustomerId WHERE ([CustomerStatus] <> @CustomerStatus) ORDER BY FullText_for_Customers.RANK DESC";

现在当GridView被拆分为CustomerID, CustomerFirstName, CustomerLastName, CustomerPickUpDay, and CustomerSignUpDate.

当我搜索时,我只搜索名字,但我必须输入完整的名字或姓氏,我不能只输入一部分;比如取我的姓,Bonilla,我必须搜索 Bonilla 才能显示结果,我不能只搜索 Bon 或 Bo 或 illa。我怎么会有这份工作?

4

1 回答 1

1

自由文本搜索实际上并不是这样工作的。但是,您可以得到一个近似值。使用 CONTAINSTABLE 代替 FREETEXTTABLE 并将星号 ( *) 附加到您的搜索词。这样,您将获得以“Bo”或“Bon”开头的名称。但是,没有办法获得以“illa”结尾的名称。

(此外,通过使用 FREETEXTTABLE,您要求数据库将您的搜索词放在同义词库中,这对于名称来说可能是个坏主意。)

于 2012-09-15T22:51:21.090 回答