I've tried -
DataGridView1.DataSource=Nothing
and
DataGridView1.DataSource=Nothing
DataGridView1.Refresh()
and
DataGridView1.RefreshEdit()
None of them works..
I've written a method that sets the DataSource of the DataGridView when executed. but each time i execute it, it replicates the data with new value and appends it to the previous contents of the DGV.. I wanna clear the content and then add the values.. Is that possible?
I had the same problem: I was programmatically binding my GridView1 to one SQL table [dictonary] or another [meny] BUT when I selected the second table from my RadioButtonList1, I was getting an error (System.Web.HttpException: Field or property with the title [the first column's title from the previously selected table] was not found in the selected data source.) i.e. saying that the columns from my first-selected table couldn't be found. All I needed to do was insert:
before adding the table columns. Here goes the full code:
Then comes your first Sub:
Then comes your second Sub:
Finally comes your RadioButton:
For completion, here is the code for the GridView1 and the RadioButtonList1 in the associated aspx.file:
This all works well now.
Don't do anything on
DataGridView
, just clear the data source. I tried clearingmyDataset.clear()
method, then it worked.1) create button named it Clear.Inside insert tfhe following code datagridviewer.DataSource=nothing
2) In your search button begin your code by the following statement
datagridviewer.DataSource = DataSet.table
Nb:instead of table put the real name of your table ex: datagridviewer.DataSource = DataSet.client
You can also try this code if you want to clear all data in your DataGridView
You can do in this way:
The mistake that you are making is that you seem to be using a dataset object for storing your data. Each time you use the following code to put data into your dataset you add data to the data already in your dataset.
If you assign the table in your dataset to a DataGridView object in your program by the following code you will get duplicate results because you have not cleared data which is already residing in your dataset and in your dataset table.
To avoid replicating the data you have to call clear method on your dataset object.
An then assign the table in your dataset to your DataGridView object. The code is like this.
You can try this code: