how to erase the previously loaded data in datagrid?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • melhanz
    New Member
    • Apr 2013
    • 4

    how to erase the previously loaded data in datagrid?

    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..
    Code:
    cnString = "server=localhost;User Id=root;database=aries_project"
                'sqlQRY = "Select * from employees_info"
    
    
                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 & " "
    
    
                conn = New MySqlConnection(cnString)
    
                'strSQL = "SELECT * from employees_info"
                conn = New MySqlConnection(cnString)
                Try
                    'Open CONNECTION
                    conn.Open()
                    da = New MySqlDataAdapter(sqlQRY, conn)
                    'create command builder
                    Dim cb As MySqlCommandBuilder = New MySqlCommandBuilder(da)
                    'fill dataset
                    da.Fill(ds, "assigned")
                    DataGridView1.DataSource = ds
                    DataGridView1.DataMember = "assigned"
                Catch ex As Common.DbException
                    MsgBox(ex.ToString)
                Finally
                    'Close(CONNECTION)
                    conn.Close()
                End Try
    Last edited by acoder; Apr 3 '13, 10:39 PM.
  • vijay6
    New Member
    • Mar 2010
    • 158

    #2
    Hey melhanz, use this line before updating 'DataGridView1' which will clear all previous records of it.
    Code:
    DataGridView1.DataSource = null;

    Use like this,

    Code:
    da.Fill(ds, "assigned")
    DataGridView1.DataSource = null
    DataGridView1.DataSource = ds
    DataGridView1.DataMember = "assigned"

    Comment

    Working...