如果数据库中存在多个字符串,则搜索并显示输入的字符串? [英] Search and display the enterd string if more than 1 exist in database ?

查看:117
本文介绍了如果数据库中存在多个字符串,则搜索并显示输入的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一家商业公司制作C#Winforms应用程序.并想从sql数据库中搜索保存的客户名称,如果输入的名称存在多个数字,则显示所有结果.

I am making an application C# Winforms for a business firm. and want to search the saved customer name from the sql database and display all the results if the entered name exist more than 1 number.

推荐答案

如果我已经理解您可以正确尝试以下方法:

If I''ve understood you correctly, try something like:

select [col1], [col2], ... from [table] where [customer_id] in (1,2,3,4,5)







or

select [col1], [col2], ... from [table] where [customer_name] in (''name1'',''name2'')


看,您的问题不清楚.我对您的问题的理解方式

给定客户名称,获取与该名称匹配的所有记录?那正确吗?如果是这样

Look, your question is not clear. The way I understood your question

Given a customer name get all the records that match for that name? Is that right? if so

Select * from table where name = ''name''



为您提供所有记录.如果您想要近距离比赛,那么



gives you all the records. If you want close matches then

select * from table where name like ''name'' 



为您提供所有与您的姓名非常匹配的记录.

获得查询结果后,您需要遍历所有值以在UI中显示它们.

CP上有很多教程,例如,请看针对初学者使用ADO.NET [ ^ ]



gives you all the records that closely match your name.

Once you get the query result, you need to traverse through all the values to show them in your UI.

There are plenty of tutorial here at CP, look for example this one Using ADO.NET for beginners[^]


这样会不会:
Would something like this do:
SELECT * FROM MyTable WHERE MyTable.CustomerName LIKE 'searched_Client_Name' HAVING COUNT(*) > 1


这篇关于如果数据库中存在多个字符串,则搜索并显示输入的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆