通过首字母文本框和mysql搜索 [英] Searching by first letter textbox and mysql

查看:81
本文介绍了通过首字母文本框和mysql搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据网格和一个文本框.我也有MySql数据库的成员.因此,当我写任何数据库成员的第一个字母以显示在datagird中时,该代码是什么.

C#代码是这样的:

Hi, I have a datagird and a textbox. Also I have member in MySql Database. So which is the code when I write a first letter of any member of database to show in datagird.

C# code is like that :

_strQuery = "SELECT * FROM tblBibloteka WHERE Emri Like '%" + txtKerko.Text + "%'";



但是我对MySql有问题...一些与MySqlconnection和MySqlAdapter相关的代码....
谁能帮我吗?

---更新评论---
好的,我们到了.
我在我的应用程序(Windows窗体)中有一个datagridview,并且在mysql中有一个带有某些成员的数据库.在我的Windows窗体中,我还有一个文本框.我需要的所有代码是,当我在文本框中编写字符示例"L"时,然后在datagirdview中列出所有带有"L"的名称.因此,此文本框必须与mysql有关....我需要相应的代码.



But I have problem with MySql...Some code with MySqlconnection and MySqlAdapter....
Can anyone help me?

--- Update from comments ---
Ok here we are.
I have a datagridview in my application(windows form)and I have a database with some members in mysql. In my windows form I also have a textbox. All what I need is code that when I write the character example ''L'' in a textbox then in datagirdview to be listed all names with ''L''. So this textbox must be related with mysql .... I need a code for that.

推荐答案

如果您正在寻找如何使SQL语句正常工作,您应该尝试以下操作:
If you are looking for just how to make the SQL statement work, you should try this:
_strQuery = "SELECT * FROM tblBibloteka WHERE Emri Like '" + txtKerko.Text + "%'";



百分号是一个通配符,这意味着如果要查找以字母开头的数据,则希望通配符仅在该字母之后出现.

但是,根据程序的工作方式以及数据库中包含的数据量,我猜测如果您掌握了所有内容,它可能会更快,更干净地运行,而不是每次都要过滤时都访问数据库,您可以过滤您已经拥有的数据.如果您已使用数据表将数据连接到数据网格,则只需设置数据表的

如果您真的想知道如何连接到MySQL ...您可以查看
http://www.connectionstrings.com/mysql [ ^ ],获取有关需要使用什么连接字符串的信息设置.您还可以在



The percent sign is a wildcard character, which means that if you are looking for data that STARTS with the letter, you want the wildcard to only appear AFTER that letter.

However, depending upon how your program works and how much data your database has, I''m guessing that it might function quicker and cleaner if you grab everything and instead of hitting the database each time you want to filter, you can just filter the data you already have. If you''ve connected your data to the DataGrid using a DataTable, you can just set the DataTable''s .DefaultView.RowFilter property[^]
You can use the .RowFilter much like the WHERE portion of an SQL statement. For example you could set it to "Emri Like''" + txtKerko.Text + "%''"

And if you''re actually wondering about how to connect to MySQL...you can check out http://www.connectionstrings.com/mysql[^] for info on what the connection string needs to be set to. You can also search on google[^] for articles on how to connect. Some of the ones listed there are even CodeProject articles.

Hope this helps.


这篇关于通过首字母文本框和mysql搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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