Hi I am trying to clear a datagridview. Here is how the datagrid is populated;
Created a clear button with this code;
Problem is that every time it returns a "System.ArgumentException was unhandled" error. So tried this;
This did not clear the datagrid at all. I am at a loss.
Thanks
VB.NET:
con.Open()
Dim myCommand As String = "select field1, field2 from table"
Dim ds As New DataSet
Dim da As New SqlDataAdapter(myCommand, con)
da.Fill(ds, "table")
con.Close()
DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = ds.Tables("table")
VB.NET:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
DataGridView1.Rows.Clear()
End Sub
VB.NET:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
DataGridView1.DataSource = Nothing
End Sub
Thanks