banner



How To Clear Datagrid In Vb Net

Member Avatar

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                    
  • 4 Contributors
  • forum 3 Replies
  • 2,706 Views
  • 3 Days Discussion Span
  • comment Latest Post Latest Post by pritesh2010

Recommended Answers

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

Jump to Post

All 3 Replies

Member Avatar

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

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

                          //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                        

Edited by pritesh2010 because: n/a

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.

How To Clear Datagrid In Vb Net

Source: https://www.daniweb.com/programming/software-development/threads/404248/clear-datagridview-vb-net

Posted by: stephensarly1995.blogspot.com

0 Response to "How To Clear Datagrid In Vb Net"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel