Results 1 to 4 of 4

Thread: database search

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    9

    database search

    Hello all!

    I am having difficulty coding for searching a database based on user entry in two textboxes. In VB6 you could do a partial searching using 'like' as soon as the user entered say 3 characters.
    Ideally, I wanted to search a database and then populate a datagrid based upon what the user enters from either box. In the load event I have the following code:

    dad(i.e. dataAdapter)
    dtb (i.e. datatable)

    cn = New OleDbConnection("Provider=SQLOLEDB;Data Source=Data3;Integrated Security=SSPI")
    cn.Open()
    SQLstr = "Select * from dbo.InstitutionTest"
    cmm = New OleDbCommand(SQLstr, cn)
    dtb = New DataTable
    dad = New OleDbDataAdapter(SQLstr, cn)
    dad.SelectCommand = cmm
    dad.Fill(dtb)

    From that point forward I wanted the first few characters entered in the textbox to immediately search the database and populate the datagrid. Any help would be great.

  2. #2
    Lively Member Atte's Avatar
    Join Date
    Feb 2004
    Posts
    79
    How about using DataView and Filter...

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    9
    I'm using Findrows which is better for what I need however, it's not finding the record.

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    9
    The following is what I have thus far:

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
    Dim dv As DataView = New DataView(ds.Tables("InstitutionTest"), "", _
    "instNbr, InstName", _
    DataViewRowState.CurrentRows)
    Dim foundRows() As DataRowView = dv.FindRows(New Object() {txtInstNbr.Text, txtInstName.Text})
    dv.Sort = "instNbr, instName"
    If foundRows.Length = 0 Then
    MsgBox("No match found.")
    Else
    Dim drv As DataRowView
    For Each drv In foundRows
    MsgBox("{0}, {1}", drv("instNbr").ToString(), drv("instName").ToString())
    Next
    End If
    End Sub

    Does anyone know why this is not finding a record and how to do a partial search?

Posting Permissions

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



Click Here to Expand Forum to Full Width