954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

clear datagridview vb.net

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
geoamins2
Light Poster
27 posts since Feb 2011
Reputation Points: 12
Solved Threads: 2
 

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

lolafuertes
Master Poster
793 posts since Oct 2008
Reputation Points: 120
Solved Threads: 166
 

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

waqasaslammmeo
Posting Pro in Training
472 posts since Aug 2011
Reputation Points: 38
Solved Threads: 82
 
//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
pritesh2010
Posting Whiz in Training
261 posts since Mar 2010
Reputation Points: 40
Solved Threads: 46
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: