5 Replies - 179 Views - Last Post: 04 February 2012 - 08:05 PM Rate Topic: -----

Topic Sponsor:

#1 bry090911  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 02-February 12

Problem Datagrid view i can't search

Posted 04 February 2012 - 09:21 AM

 Private Sub txtsearch_KeyUp(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
        Dim sqlsearch As String
        Dim com As New SqlCeCommand

        sqlsearch = "select * from tbl_philhealth where tmc like '" & txtsearch.Text & "%';"
        Using con As SqlCeConnection = New SqlCeConnection("Data Source=" & My.Settings.PATSDB)

            Try
                With com
                    con.Open()
                    com.CommandType = CommandType.Text
                    com.CommandText = sqlsearch
                    com.Connection = con
                End With

            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error!")
            Finally
                com.ExecuteNonQuery()
            End Try

        End Using
    End Sub



in datagridview if i search in the textbox i want to see the thing that i put in the textbox.. :sweatdrop:

Is This A Good Question/Topic? 0
  • +

Replies To: Problem Datagrid view i can't search

#2 nK0de  Icon User is offline

  • can't spell BITCH without IT
  • member icon

Reputation: 183
  • View blog
  • Posts: 732
  • Joined: 21-December 11

Re: Problem Datagrid view i can't search

Posted 04 February 2012 - 09:29 AM

So what's the problem? Any errors you're getting?

and by just looking at your code, I spotted that you have a syntax error in your SQL query. Missing a %. It should be like this,

]"select * from tbl_philhealth where tmc like '%" & Trim(txtsearch.Text) & "%'"

since your question is vague, I'll give a vague answer. To accomplish what I think you're trying to do, use SqlDataReader. And put the code inside the Textbox's TextChanged event.

This post has been edited by nK0de: 04 February 2012 - 11:03 AM

Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 960
  • View blog
  • Posts: 3,354
  • Joined: 25-September 09

Re: Problem Datagrid view i can't search

Posted 04 February 2012 - 10:54 AM

nK0de, that's not an error. What you have will find a matching result anywhere in the column, what the OP had will only find results in the column that Starts With what is queried.

This post has been edited by CharlieMay: 04 February 2012 - 10:55 AM

Was This Post Helpful? 2
  • +
  • -

#4 nK0de  Icon User is offline

  • can't spell BITCH without IT
  • member icon

Reputation: 183
  • View blog
  • Posts: 732
  • Joined: 21-December 11

Re: Problem Datagrid view i can't search

Posted 04 February 2012 - 10:59 AM

View PostCharlieMay, on 04 February 2012 - 11:24 PM, said:

nK0de, that's not an error. What you have will find a matching result anywhere in the column, what the OP had will only find results in the column that Starts With what is queried.


crap! :facepalm: You're right! I can't believe it slipped my mind! sorry bry090911.

This post has been edited by nK0de: 04 February 2012 - 11:10 AM

Was This Post Helpful? 0
  • +
  • -

#5 bry090911  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 02-February 12

Re: Problem Datagrid view i can't search

Posted 04 February 2012 - 07:08 PM

so whats the problem here? :blink:
Was This Post Helpful? 0
  • +
  • -

#6 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1644
  • View blog
  • Posts: 4,126
  • Joined: 14-March 10

Re: Problem Datagrid view i can't search

Posted 04 February 2012 - 08:05 PM

You better tell us what is the problem you have. What is your code doing which is not expected and what you wanted it to do? Also if you have any error message please explain to us the errors and where they occur.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1