1.11M Members

clear datagridview vb.net

 
0
 

Could you please tell me how to clear the old data from the datagridview in vb.net..
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
c.myCon()
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
 
0
 

Did you refresh the dgExperience after assigning the data source?

dgExperience.Refresh

Also the

dgExperience.Rows.Clear

before assigning the new data source, can help.

Hope this helps

 
0
 

hi !
try this code

datagridview1.rows.clear()

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

Regards .
M.Waqas Aslam

 
0
 
//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
else
dgExperience.DataSource = null
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: