有没有一种简单的方法可以在vb.net中搜索代码? [英] Is there an easy way for searching codes in vb.net?

查看:84
本文介绍了有没有一种简单的方法可以在vb.net中搜索代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!
我希望有人能帮助我,我正在尝试创建一种有效的方式来搜索数据库中的记录.例如:我有一个包含课程列表的表,在我的系统中,我将允许用户检查他们想要的课程是否已经在数据库中.

首先,我向用户显示所有可用课程列表,并且有一个文本框,他们可以在其中输入单词/课程,这些单词/课程将从数据库中搜索并显示在网格中.查看所有匹配的课程,或者完全匹配或仅包含某些单词匹配项.

我尝试使用正则表达式获取每个单词,我设法让用户键入的每个单词现在要发生的事情是搜索此单词以查找数据库中的匹配课程.但是我无法在gridview中显示选定的数据.希望你能帮我..

非常感谢.

Good Day!
I hope someone can help me, I am trying to create an efficient way of searching records in my database. For Example: I Have Table that contains the list of courses, in my system I will allow users to check if the course they wanted is already in the database.

At first, I am showing the user all the list of available courses and there is a textbox where in they can type words/course that will search from the database and will be displayed in the gridView all matching courses either perfect match or some words only matches.

I tried getting each words using regex and i manage to get each word typed by the user what i want to happen now is to search this words for matching courses in the database. but i can''t show the selected data in the gridview. Hope you can help me..

Thank you very much.

Dim myMatches As MatchCollection
        Dim myRegex As New Regex("\w+")
        Dim t As String
        t = TextBox5.Text
        myMatches = myRegex.Matches(t)
        ' Search for all the words in a string
        Dim successfulMatch As Match
        For Each successfulMatch In myMatches
            ListBox1.Items.Add(successfulMatch.Value)
            Dim sql As String = " Select * from Courses_Tbl where Crs_Desc Like ''"& t &"'%' or  Crs_Desc Like '%'"& t &"''"
        Dim adp As New SqlDataAdapter(sql, con)
        Dim com As New SqlCommand(sql, con)
       Dim adp As New SqlDataAdapter(sql, con)
        Dim ds As New DataTable
       adp.Fill(ds)

        Next
        GridView2.DataSource = ds
        GridView2.DataBind()

        Next
        GridView2.DataSource = ds
        GridView2.DataBind()

推荐答案

首先,我注意到您使用过select *.
您真的需要从表返回的所有记录吗?

尝试仅返回查询中应用程序实际需要的那些记录.

第二件事可能是确保为表建立索引,以确保使用where子句进行更好的过滤.

您可能还需要考虑一次加载所有数据,然后在UI上进行过滤的方法,而不是每次都向数据库发送查询.不过,并不总是建议这样做,这种策略也有优点和缺点.
First off, I noticed you have used select *.
Do you really need all records returned from the table?

Try and return only those records in the query that are actually needed by your application.

The second thing could be to make sure the table is indexed to ensure better filtering using the where clause.

You might also want to consider the approach of loading all the data once and then filtering on the UI rather than sending a query to the database every single time. This is not always recommended though, and there are pros and cons for this strategy.


感谢您的回复AbhinavS.非常感谢您的帮助.我将再次进行审查.

谢谢.
Thank you for your reply Abhinav S. I really appreciate your help. I will review this again.

Thank you.


这篇关于有没有一种简单的方法可以在vb.net中搜索代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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