如何在数据库中搜索值 [英] How to Search a value in a data base

查看:92
本文介绍了如何在数据库中搜索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试创建一个应用程序,如果用户在文本框中输入数字,然后按一个按钮,它将搜索我的sql数据库文件data.mdf并显示该特定唯一编号的人的姓名.在文本框中输入.

任何人都可以告诉我按钮的编码吗?

我是新手,请尝试帮助...


谢谢

Hi There,

I am trying to make an application where if the user enters a number in a text box and then presses a button then it will search my sql database file data.mdf and will display the name of the person of that particular unique no. entered in the text box.

Can Anyone please tell me the coding for the button.

I am a Newbie so please try to help...


THANKS IN ADVANCE

推荐答案

尝试在 ^ ]或CodeProject中的文章.

这一个 [
Try searching for some articles on Google [^]or the articles in CodeProject.

This one[^] looks like a good start for you.


您需要SQL查询数据库. br/> 例如,在您的情况下:SELECT NameOfThePerson WHERE ID = YourTextBoxValueAsInteger

要执行查询,您需要在应用程序中进行编码,执行一些操作,例如打开数据库,查询并关闭.

如果您在某些引擎中搜索"C#SQL查询",则会发现很多示例...
You need SQL to query the database.
For example in your case : SELECT NameOfThePerson WHERE ID=YourTextBoxValueAsInteger

For executing the query you need coding in your application, do some thing like open the database, query it and close.

If you search "C# SQL QUERY" in some engine you find a lot of examples ...


或者...也许这可以帮助您入门?

Or...maybe this can get you started?

' If search box is empty
If SearchBox.Text = "" Then
   ' Bring up all names
   Me.BindingSource1.Filter = "UniqueID like '" & "%" & "'"
Else
   ' Bring up name being searched for
   Me.BindingSource1.Filter = "UniqueID like '" & "%" & SearchBox.Text & "%" & "'"
End If



不确定这是您要找的东西,但这是一个主意.

[已修改以指定pre块的语言,以便可以正确设置颜色格式]



Not sure this is what you are looking for, but here is an idea.

[Modified to specify the language for the pre block so that it will be color-formatted correctly]


这篇关于如何在数据库中搜索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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