search dialog box

  • Thread starter Thread starter Martin Williams
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top