Hello,
I have a datagridview and a search textbox that filters the dgv on button click with whatever the user inputs in that textbox.
The problem is, when the user tries to update a row AFTER a search, the datarow grabbed is NOT the current one but the one that was selected BEFORE the search.
I think this is because I am creating 2 datatables (one for form_load and another for the search filter), and the user hits the update button, the row grabbed is from the form_load datatable.
Please take a look at my (simplified) code below:
Thanks for your help.Code:Public Class VBApp Private Sub fetchData(ByVal tableName As String) Dim dt As New DataTable adapter = New MySqlDataAdapter command.Connection = conn command.CommandText = "select * from TableName" adapter.SelectCommand = command reader = command.ExecuteReader dt.Load(reader) DataGridView1.DataSource = dt reader.Close() conn.Close() End Sub Private Sub updateData() Dim row As DataRow = DirectCast(BindingSource.Current, DataRowView).Row Using dialogue As New updatePopup(row) Dim dr As DialogResult = dialogue.ShowDialog() End Using 'etc. etc. (skipping code) Private Sub searchData() Dim search As String = KeywordTextbox.Text Dim tableName As String = TableList.Text Dim dt As New DataTable If (conn.State = ConnectionState.Closed) Then setConnection() End If command.Connection = conn command.CommandText = "" command.CommandText = "select * from persons where `columnA` like '%" & search "%'" reader = command.ExecuteReader dtable.Load(reader) DataGridView1.DataSource = dt reader.Close() conn.Close() End Sub End Class




Reply With Quote
