简体   繁体   English

在 UWP 应用中实现搜索功能以从 SQL 服务器中查找数据

[英]Implement a search Function to find data from SQL server in UWP app

I created a table in SQL server and I linked it to my UWP app, using the method from Microsoft website : https://docs.microsoft.com/en-us/windows/uwp/data-access/sql-server-databases Now my question is, how will I be able to implement a search function?我在 SQL Server 中创建了一个表,并将其链接到我的 UWP 应用程序,使用来自 Microsoft 网站的方法: https : //docs.microsoft.com/en-us/windows/uwp/data-access/sql-server-databases现在我的问题是,我将如何实现搜索功能? for example the user types The name it should bring the results back.例如用户输入的名字应该带回结果。 I intend to use a search box or a text box.我打算使用搜索框或文本框。

As a starting point, take a look at https://www.w3schools.com/sql/sql_like.asp作为起点,请查看https://www.w3schools.com/sql/sql_like.asp

You can build your statement around this.您可以围绕此构建您的声明。

SELECT * FROM Products WHERE ProductDescription LIKE '%textboxinput';

This example finds any values that end with "textboxinput".此示例查找以“textboxinput”结尾的任何值。 You can play around with the wildcards mentioned in the link to get the desired behaviour.您可以使用链接中提到的通配符来获得所需的行为。

Going by the code in your link, you can then go and just clone your GetProducts() Method, rename and edit it to fulfill your needs.通过链接中的代码,您可以去克隆您的 GetProducts() 方法,重命名和编辑它以满足您的需求。 In particular, the constant GetProductsQuery needs to be edited with the appropriate sql statement mentioned above.特别是,常量 GetProductsQuery 需要使用上面提到的适当的 sql 语句进行编辑。

If you would for example search for 'ng' as your input, only the datasets with the ids 2 4 would be selected.例如,如果您要搜索 'ng' 作为输入,则只会选择 ID 为 2 4 的数据集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM