|
-
Mar 23rd, 2004, 03:47 PM
#1
Thread Starter
New Member
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.
-
Mar 23rd, 2004, 04:53 PM
#2
Lively Member
How about using DataView and Filter...
-
Mar 24th, 2004, 10:41 AM
#3
Thread Starter
New Member
I'm using Findrows which is better for what I need however, it's not finding the record.
-
Mar 24th, 2004, 10:57 AM
#4
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|