hi every 1. i have a form and i dropped customer dataset as details view on the form and booking dataset as gridview.So now when i insert a record i can scroll through different records and with respect to the customer its shows me related booking aswell. Wat i wanna do is i want to create a search txt box where i can bind both detailsview and data gridview. i knw how to write code for gridview but really struggling to change the data for both..here i wrote code for gridview plz add or modily the code..So that when i search through 100 of records i can see customer details in details view and customer booking on gridview.thnx

Dim dv As DataView = New DataView()

dv.Table = NewBookingDataSet.Customer


dv.RowFilter = "LastName like '%" & txtCustSearchNewBooking.Text & "'"

NewBookingDataGridView.DataSource = dv

Recommended Answers

All 9 Replies

You would like to get only the rows of customers that have the written lastname in textBox, if I got you right?

This means you have to do the filtering over dataSet to get new DataRows (array of them) and them convert this array back to dataset to bind it again with datagridview.
This can be done like this.

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
            table.ImportRow(row)
        Next
        'bind new datasource to dgv:
        dataGridView.DataSource = Nothing
        'resetting datasource
        dataGridView.DataSource = ne
        BindingSource(tableNew, Nothing)
    End Sub

This should do it.

Last name is my search criteria..based on the matching last name of the customer. i want to show all the customer data like firtname,lastname,telephone in the details view that are the text boxes and below is the datagridview..where i want to show customer with related booking..So wana show two things depending on last name. Customer_id is a foreign key in booking table.

Based on my previous code:

....
For Each row As DataRow In rows
	table.ImportRow(row)
Next
'pass the data from table to textboxes:
textBoxName.Text = tableNew.Rows(0)(0)
' 1st zero is row index, 2nd zero is column index - 1st row and 1st column
'for other do the same...

hi there i just modified your code but still getting plenty of errors..cant figure our.here is my modified code.could u help plz

Private Sub DoTheFiltering()
Dim ds As DataSet
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
booking.ImportRow(row)
Next
'pass the data from table to textboxes:
Cust_idTextBox.Text = tableNew.Rows(0)(0)
'bind new datasource to dgv:
NewBookingDataGridView = Nothing
'resetting datasource
NewBookingDataGridView.DataSource = ne
BookingBindingSource(tableNew, Nothing)
End Sub

i have placed this code and i removed the last two line where it says datagridview=nothing

it is not giving me any error now but when i enter last name in the search box its not giving me any resluts inshort nothing happening..plz help here is the code

Dim ds As DataSet
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
NewBookingDataSet.Booking.ImportRow(row)
Next
'pass the data from table to textboxes:
Cust_idTextBox.Text = tableNew.Rows(0)(0)
'bind new datasource to dgv:
NewBookingDataGridView = Nothing
'resetting datasource

End Sub

Please write some notes on the lines where errors are.

first of all when i place this code inside the search text box it asks me to move private sub function separately. so i have to place it separate to avoide the erros. 2nd thing which i cannot understand here is "table new" and "selected customers" what shall i replace here. and the last two lines where it says =ne it says "ne is not declared."

1 more error which i cannot figure out is the last line
BookingBindingSource(tableNew, Nothing)

property access must assign a value

i have done it ..its just 1 line of code which i was looking for
Me.CustomerBindingSource.Filter = "LastName= '" & Me.txtCustSearchNewBooking.Text & "'"

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.