dcsimg
Results 1 to 7 of 7

Thread: [RESOLVED] vb.net search textbox slow

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2015
    Posts
    95

    Resolved [RESOLVED] vb.net search textbox slow

    hi,
    is this code make my search db slow or am wrong with this code ?
    an which better
    second, and sometime when i search first name
    if there is like

    ahmed hamad
    kankon blabla
    hamad zero

    when i search for hamad i get ( ahmed hamad )


    Code:
     Private Sub TextBox20_TextChanged(sender As Object, e As EventArgs) Handles TextBox20.TextChanged
            Try
                Table_infonameBindingSource.Filter = "(name LIKE '%" & TextBox20.Text & "%')" & "OR (civilid Like '%" & TextBox20.Text & "%')"
            Catch ex As Exception
            End Try
    End Sub
    also i did try with qury very slow this code qury search name
    Code:
    WHERE        (name LIKE N'%' + @PARAM1 + N'%')
    with code search
    Code:
     Private Sub TextBox4_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox4.TextChanged
     Try
    
                If Table_infonameTableAdapter.FillByname(KankonDataSet.Table_infoname, TextBox4.Text) Then
    
                Else
    
                    If Table_infonameTableAdapter.FillBymobile(KankonDataSet.Table_infoname, TextBox4.Text) Then
    
                    Else
    
                        If Table_infonameTableAdapter.FillBycivilid(KankonDataSet.Table_infoname, TextBox4.Text) Then
    
                        Else
                        End If
                    End If
                End If
    
            Catch ex As Exception
    
            End Try
     End Sub

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,922

    Re: vb.net search textbox slow

    Empty catch blocks can make your program SUPER slow. You'd never know if there was an exception, and exceptions are about as slow as things can get. In this case, an exceptions seems unlikely, so the slowdown is probably due to the nature of the search itself, but having empty catch blocks is a really bad idea.

    As to the search, you are doing LIKE queries, which aren't all that fast. If there is a considerable amount of data, the search could simply be slow. How many records are being searched?
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2015
    Posts
    95

    Re: vb.net search textbox slow

    Quote Originally Posted by Shaggy Hiker View Post
    Empty catch blocks can make your program SUPER slow. You'd never know if there was an exception, and exceptions are about as slow as things can get. In this case, an exceptions seems unlikely, so the slowdown is probably due to the nature of the search itself, but having empty catch blocks is a really bad idea.

    As to the search, you are doing LIKE queries, which aren't all that fast. If there is a considerable amount of data, the search could simply be slow. How many records are being searched?
    like 240

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,380

    Re: vb.net search textbox slow

    My guess is that the search itself isn't slow...in that first code block, you're filtering against a bindingsource... so it's all client side... it's not actually doing anything to the data, it's all against the biding source... so that's about as good as it gets... I'd go ahead and drop the try...catch at least for now... see if that helps... I don't think it will change anything unless there's exceptions that aren't being caught (since the catch is empty) ...

    What isn't known is what else is bound to that bindingsource... it maybe that that's the slowdown... which is what brings me to my next question: what makes you think it's slow? Have you try debugging it to see where the slowdown is? My suspicions are that the filtering is actually quick, but the side effect is that theUI then has to re-render, which is expensive, and that's the slowdown you're seeing.

    As for your "problem" when searching by first name... it's because you're searching by the whole name... not "just" the first name... if they were in two fields (first_name & last_name) then it would be possible. but since it appears you have them all in one field, it becomes harder. You'd have to change the filter:
    Code:
    Table_infonameBindingSource.Filter = "(name LIKE '" & TextBox20.Text & "%')" & "OR (civilid Like '%" & TextBox20.Text & "%')"
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2015
    Posts
    95

    Re: vb.net search textbox slow

    Quote Originally Posted by techgnome View Post
    My guess is that the search itself isn't slow...in that first code block, you're filtering against a bindingsource... so it's all client side... it's not actually doing anything to the data, it's all against the biding source... so that's about as good as it gets... I'd go ahead and drop the try...catch at least for now... see if that helps... I don't think it will change anything unless there's exceptions that aren't being caught (since the catch is empty) ...

    What isn't known is what else is bound to that bindingsource... it maybe that that's the slowdown... which is what brings me to my next question: what makes you think it's slow? Have you try debugging it to see where the slowdown is? My suspicions are that the filtering is actually quick, but the side effect is that theUI then has to re-render, which is expensive, and that's the slowdown you're seeing.

    As for your "problem" when searching by first name... it's because you're searching by the whole name... not "just" the first name... if they were in two fields (first_name & last_name) then it would be possible. but since it appears you have them all in one field, it becomes harder. You'd have to change the filter:
    Code:
    Table_infonameBindingSource.Filter = "(name LIKE '" & TextBox20.Text & "%')" & "OR (civilid Like '%" & TextBox20.Text & "%')"
    -tg
    probably from sql server db , bec i make new form its same slow
    check video the search box when i write slow
    https://files.fm/f/ryy2j7qu
    Last edited by kankon; Feb 11th, 2019 at 04:04 PM. Reason: add video

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,922

    Re: vb.net search textbox slow

    That's a tiny number of records, so the size of the search isn't an issue.

    Frankly, the video didn't make it seem all that slow, to me. There is a bit of a pause, but that could be due to rendering rather than the search, as TG said. Figuring out which it is could be a bit difficult. The first step is to get rid of the Try...Catch blocks. You don't want those in any case, because there isn't anything exceptional in the code: If it crashes, it's because of a bug that can be fixed, not because the environment did something surprising (like a file being deleted as it is read, or a database suddenly going away unexpectedly). If you remove the Try....catch blocks and nothing changes, at least you know there weren't exceptions causing the problem. Catching exceptions is costly, having a try...catch that never catches anything costs nothing. So, if they aren't doing any good, then they aren't doing any harm, either, in which case you have to look at the binding. However, if they are actually catching exceptions, then that will be slow.

    Most likely, though, it has to do with the rendering of the form, and that won't be so easy to track down, and may not be something that can be fixed.
    My usual boring signature: Nothing

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2015
    Posts
    95

    Re: vb.net search textbox slow

    Quote Originally Posted by Shaggy Hiker View Post
    That's a tiny number of records, so the size of the search isn't an issue.

    Frankly, the video didn't make it seem all that slow, to me. There is a bit of a pause, but that could be due to rendering rather than the search, as TG said. Figuring out which it is could be a bit difficult. The first step is to get rid of the Try...Catch blocks. You don't want those in any case, because there isn't anything exceptional in the code: If it crashes, it's because of a bug that can be fixed, not because the environment did something surprising (like a file being deleted as it is read, or a database suddenly going away unexpectedly). If you remove the Try....catch blocks and nothing changes, at least you know there weren't exceptions causing the problem. Catching exceptions is costly, having a try...catch that never catches anything costs nothing. So, if they aren't doing any good, then they aren't doing any harm, either, in which case you have to look at the binding. However, if they are actually catching exceptions, then that will be slow.

    Most likely, though, it has to do with the rendering of the form, and that won't be so easy to track down, and may not be something that can be fixed.
    work now , better then before , thanks guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width