Start New Discussion within our Software Development Community

Could you please tell me how to clear the old data from the datagridview in
the below code is retrieving the data from table and display in a gridview for particular person. but when i wanna check the next person record if he dosen't have record so the previous data still will not erased?

Dim c As New sqlStmt
Dim da As New SqlDataAdapter("SELECT * FROM Experience WHERE CID='" & Trim(txtCID.Text) & "'", c.con)
Dim ds As New DataSet("ManPower")
da.Fill(ds, "ManPower")
dgExperience.DataSource = ds.Tables("ManPower").DefaultView

Did you refresh the dgExperience after assigning the data source?


Also the


before assigning the new data source, can help.

Hope this helps

hi !
try this code


it will remove all the rows then assign new data to it
Hope this will helps u

Regards .
M.Waqas Aslam

//whenever you are trying to bind DataTable to Datagridview
//First of all make Datagridview  datasource null;
//set the 
dgExperience.DataSource = null
// then write your code
// and even you can check your DataTable Like
DataTable _DataTable=new DataTable(); 
if( _DataTable!=null || _DataTable.Rows.Count !=0) then
// bind your grid with datatable or dataset
dgExperience.DataSource = null
This article has been dead for over six months. Start a new discussion instead.