search dialog box

M

Martin Williams

Trying to make a search box to examine the records of a dataset. Here's my
code so far:

sub SearchForCustomer()

dim intCount as integer
dim SearchText as string
dim Customer as datatable
dim CurrentRow as datarow

customer = dataset.customer
SearchText = inputbox("Enter the last name of the customer","Search")
for intCount = 0 to customer.rows.count -1
CurrentRow = customer.rows(intcount)
if customer.rows.item("Last Name").tostring = SearchText then
me.bindingcontext(Customer).position = intcount
end if
next

end sub

Appreciate all responses.

Regards,
Martin Williams
 
K

Ken Tucker [MVP]

Hi,

The dataview has a find method. It will find a record in a sorted
column. Here is an example. I assume you have imports system.data.oledb at
the top of the file.

Dim conn As OleDbConnection

Dim strConn As String

Dim strSQL As String

Dim ds As New DataSet

Dim da As OleDbDataAdapter

Dim dv As DataView

Dim cm As CurrencyManager

Dim iRow As Integer

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn += "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

da = New OleDbDataAdapter("Select * from Orders", conn)

da.Fill(ds, "Customers")

dv = New DataView(ds.Tables("Customers"))

DataGrid1.DataSource = dv

dv.AllowNew = False

cm = CType(Me.BindingContext(dv), CurrencyManager)

dv.Sort = "CustomerID"

Dim x As Integer

x = dv.Find("VINET")

cm.Position = x



Ken
 
M

Martin Williams

Thanks for your reply, Ken. In your example, you assign the datasource of a
datagrid to dv. In my program, I am working with multiple bound text boxes.
How would I adapt what's below to that? Thanks.

Regards,
Martin Williams
 
K

Ken Tucker [MVP]

Hi,

Sure. Bind the textboxes to the dataview instead.

Ken
----------------------
Martin Williams said:
Thanks for your reply, Ken. In your example, you assign the datasource of a
datagrid to dv. In my program, I am working with multiple bound text boxes.
How would I adapt what's below to that? Thanks.

Regards,
Martin Williams

Ken Tucker said:
Hi,

The dataview has a find method. It will find a record in a sorted
column. Here is an example. I assume you have imports
system.data.oledb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top