By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,953 Members | 1,131 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,953 IT Pros & Developers. It's quick & easy.

how to erase the previously loaded data in datagrid?

P: 4
everytime i load the data to datagrid the previous data is added wid the recent data?

how erase the previously loaded data in datagird?

my code is..
Expand|Select|Wrap|Line Numbers
  1. cnString = "server=localhost;User Id=root;database=aries_project"
  2.             'sqlQRY = "Select * from employees_info"
  3.  
  4.  
  5.             sqlQRY = "SELECT assigned.id,assigned.emp_id,assigned.itemno,inventory.`description`,assigned.`quantity`,inventory.amount,inventory.`amount`* assigned.`quantity` AS Amount,assigned.remarks,assigned.datetime FROM `aries_project`.`employees_info` INNER JOIN `aries_project`.`assigned` ON (`employees_info`.`emp_id` = `assigned`.`emp_id`) INNER JOIN `aries_project`.`inventory` ON (`assigned`.`itemno` = `inventory`.`itemno`) WHERE assigned.emp_id=" & Label1.Text & " "
  6.  
  7.  
  8.             conn = New MySqlConnection(cnString)
  9.  
  10.             'strSQL = "SELECT * from employees_info"
  11.             conn = New MySqlConnection(cnString)
  12.             Try
  13.                 'Open CONNECTION
  14.                 conn.Open()
  15.                 da = New MySqlDataAdapter(sqlQRY, conn)
  16.                 'create command builder
  17.                 Dim cb As MySqlCommandBuilder = New MySqlCommandBuilder(da)
  18.                 'fill dataset
  19.                 da.Fill(ds, "assigned")
  20.                 DataGridView1.DataSource = ds
  21.                 DataGridView1.DataMember = "assigned"
  22.             Catch ex As Common.DbException
  23.                 MsgBox(ex.ToString)
  24.             Finally
  25.                 'Close(CONNECTION)
  26.                 conn.Close()
  27.             End Try
Apr 3 '13 #1
Share this Question
Share on Google+
1 Reply


100+
P: 158
Hey melhanz, use this line before updating 'DataGridView1' which will clear all previous records of it.
Expand|Select|Wrap|Line Numbers
  1. DataGridView1.DataSource = null;

Use like this,

Expand|Select|Wrap|Line Numbers
  1. da.Fill(ds, "assigned")
  2. DataGridView1.DataSource = null
  3. DataGridView1.DataSource = ds
  4. DataGridView1.DataMember = "assigned"
Apr 3 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.