hi every 1 i am trying to make a search criteria based on last name.i have dragged and dropped customer dataset as details view on my form and booking as gridview(customer id is foreign key in bookings table so now when i scroll through customer i could see the relaive booking history in grid view.). now i have many customer so i have to scroll down to look for a particular customer. i want to create a textbox where i can enter customer's last name and it should change the data of details view from current customer to the customer which is searched and also should change the related data in gridview aswell which is customer booking data.really need help plz..provide code if u can..here is wat i have done but no luck.

Dim ds As DataSet
'** means:
'check for correct name of the table in dataset, you can still use index like [0] if this is 1st or only table in dataset


'class variable where you have all the data of customers and its bind to datagridview
Private Sub DoTheFiltering()
Dim filter As String = txtCustSearchNewBooking.Text
Dim query As String = "LastName like '%" & filter & "'"
Dim rows() As DataRow = ds.Tables("Customers").Select(query)
'**
Dim tableNew As DataTable = New DataTable("SelectedCustomers")
'create columns for table:
For Each column As DataColumn In ds.Tables("Customers").Columns
tableNew.Columns.Add(New DataColumn(column.ColumnName, GetType(System.String)))
Next
'adding rows to table:
For Each row As DataRow In rows
new_bookingdataset.booking.ImportRow(row)
Next

dataGridView.DataSource = Nothing
'resetting datasource
dataGridView.DataSource = ne
BindingSource(tableNew, Nothing)
End Sub

Recommended Answers

All 3 Replies

hi every 1 i am trying to make a search criteria based on last name.i have dragged and dropped customer dataset as details view on my form and booking as gridview(customer id is foreign key in bookings table so now when i scroll through customer i could see the relaive booking history in grid view.). now i have many customer so i have to scroll down to look for a particular customer. i want to create a textbox where i can enter customer's last name and it should change the data of details view from current customer to the customer which is searched and also should change the related data in gridview aswell which is customer booking data.really need help plz..provide code if u can..here is wat i have done but no luck.

Dim ds As DataSet
'** means:
'check for correct name of the table in dataset, you can still use index like [0] if this is 1st or only table in dataset


'class variable where you have all the data of customers and its bind to datagridview
Private Sub DoTheFiltering()
Dim filter As String = txtCustSearchNewBooking.Text
Dim query As String = "LastName like '%" & filter & "'"
Dim rows() As DataRow = ds.Tables("Customers").Select(query)
'**
Dim tableNew As DataTable = New DataTable("SelectedCustomers")
'create columns for table:
For Each column As DataColumn In ds.Tables("Customers").Columns
tableNew.Columns.Add(New DataColumn(column.ColumnName, GetType(System.String)))
Next
'adding rows to table:
For Each row As DataRow In rows
new_bookingdataset.booking.ImportRow(row)
Next

dataGridView.DataSource = Nothing
'resetting datasource
dataGridView.DataSource = ne
BindingSource(tableNew, Nothing)
End Sub

I have done the same thing for my doctorsearch...

In combo box I had the items as ID, FirstName, LastName

and in the Textbox that is the search box...

i have written the coding in Textbox_Text change event....

If cboDoctorSearch.SelectedItem = "Doctor ID" Then
            Try
                Dim myCommand As New OleDbCommand
                With myCommand
                    .CommandText = "SELECT DoctorID , (FirstName +' '+LastName) as DrName,PhoneNo,MobNo,LicenseNo FROM DoctorRegister where  DoctorID like '" & txtSearchFor.Text & "%" + "' order by DoctorID"
                    .CommandType = CommandType.Text
                    .Connection = Connection
                End With
                Dim dt As New DataTable
                dt.Load(myCommand.ExecuteReader)
                With dgvDocSearch
                    .AutoGenerateColumns = True
                    .DataSource = dt
                End With
            Catch ex As Exception
                MsgBox("Error in select query: " + ex.Message)
            End Try
        ElseIf cboDoctorSearch.SelectedItem = "First Name" Then
            Try
             ''''so on so forth....

Give it a try

did u drop the dataset first on the form and than used this coding under the textbox which u used for the search. i m just confused about the result display.where your query is going to display the result..is it a gridview where u will be displaying the result?

did u drop the dataset first on the form and than used this coding under the textbox which u used for the search. i m just confused about the result display.where your query is going to display the result..is it a gridview where u will be displaying the result?

Yes the result will be displayed in the datagridview....

no need to drop the dataset on the form....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.