Hi I have used the following code to populate a DataGrid based on the contents of a textbox. the users searches for a name which is populated into a combobox based on the name in the combobox several textboxes are populated with data based on the data in one of these text boxes
Private bindingSource1 As New BindingSource
Private Sub BindData()
Dim connString As String = My.Settings.strConn
Dim conn As New SqlConnection(connString)
Try
conn.Open()
myDA = New SqlDataAdapter("SELECT t_id, firstName, lastName, rentPaid, datePaid, propRef, dayDue, rentDue FROM payments WHERE t_id = '" & TextBoxTenantIdSearchExist.Text & "'", connString)
Dim builder As SqlCommandBuilder = New SqlCommandBuilder(myDA)
myDA.Fill(mydataset, "payments")
bindingSource1.DataSource = mydataset.Tables("payments")
Catch ex As Exception
My.Computer.Audio.Play(My.Resources.femaleerror, AudioPlayMode.WaitToComplete)
DesktopAlert1.Show()
DesktopAlert1.CaptionText = "Sorry!"
DesktopAlert1.ContentText = "Error: " + ex.Source + ": " + ex.Message
bindingSource1.DataSource = Nothing
Finally
conn.Close()
End Try
End Sub
DataGridViewSearchExist.DataSource = bindingSource1
Private Sub TextBoxTenantIdSearchExist_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxTenantIdSearchExist.TextChanged
BindData()
Label75.Text = "Total Rent Paid: " & bindingSource1.DataSource.Compute("SUM(rentPaid)", String.Empty)
End Sub
it all works fine except if I alternate between the names it just keeps adding to the gridview is there a way I can clear the gridview before it gets populated?
see this image
[IMG]http://img189.imageshack.us/img189/3161/screenwxu.png[/IMG]
I have tried
bindingSource1.DataSource = Nothing
DataGridViewSearchExist.DataBindings.Clear()
DataGridViewSearchExist.Refresh()
none of those cleared the contents first I placed them here
Private Sub BindData()
bindingSource1.DataSource = Nothing
DataGridViewSearchExist.DataBindings.Clear()
DataGridViewSearchExist.Refresh()
any ideas thanks
M