1,105,352 Community Members

clear datagridview vb.net

Member Avatar
geoamins2
Light Poster
30 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
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
Member Avatar
lolafuertes
Posting Shark
912 posts since Oct 2008
Reputation Points: 145 [?]
Q&As Helped to Solve: 196 [?]
Skill Endorsements: 7 [?]
 
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

Member Avatar
M.Waqas Aslam
Practically a Posting Shark
837 posts since Aug 2011
Reputation Points: 67 [?]
Q&As Helped to Solve: 137 [?]
Skill Endorsements: 4 [?]
Featured
 
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

Member Avatar
pritesh2010
Posting Whiz in Training
265 posts since Mar 2010
Reputation Points: 30 [?]
Q&As Helped to Solve: 46 [?]
Skill Endorsements: 0 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: