0
I’m trying to create a function to update Datagridview. I added the following code but gave an error "Unable to clear the list"
Code:
Private Sub GetData()
Try
con = New SqlConnection(cs)
con.Open()
cmd = New SqlCommand("SELECT nome, matricula, marca, [Licenca-emissao], [licenca-expira] from Clientes order by Nome", con)
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
dgw.Rows.Clear()
While (rdr.Read() = True)
dgw.Rows.Add(rdr(0), rdr(1))
End While
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
you are setting your dgw’s Datasource somewhere before?
– Bruno Piovan
@Brunopiovan did not realize the "SETANDO"
– Abd Domingos
vc is assigning the previously Datasource property somewhere else?
– Bruno Piovan
@Brunopiovan Yes, in various Forms
– Abd Domingos
That’s why you can’t clean the Rows because there is an assigned datasource, you have to clean the "Rows" from your datasource. I will respond with a recommendation.
– Bruno Piovan
@Brunopiovan am an amateur developer yet, could make it a little easier. And I notice more programming in English
– Abd Domingos
ok! check These out, Might help http://stackoverflow.com/questions/6184402/how-can-i-clear-rows-in-datagridview-with-c http://stackoverflow.com/questions/18151641/filling-a-datagridview-from-sqlreader
– Bruno Piovan
Thanks, but this is C#, I’ve never touched C# @Brunopiovan
– Abd Domingos
I tried using the function datatable.Clear dataGridView.Refresh More didn’t work
– Abd Domingos