clear the datagridview

Jun 18 2011 7:56 AM
  I have a form with textbox and datagridview ,when we enter the value into the textbox ,corresponding values filled into the datagridse view. i use this code for this , but here arise one problem when we change the value of textbox, the datagridview values not cleared, the  Previous  values also displayed in to the datagridview. how we clear the  datagridview , when we enter the value  2nd time into textbox.


    private void textBox2_TextChanged(object sender, EventArgs e)

        {

            lpogridview.Visible = true;

             lpogridview.DataSource = null;

                cmd.CommandText = "select itemcode,itemname,unit,lpoqty,lporate,lpodiscount,lpovalue from lpo l inner join item i on l.itemid=i.itemid where lpono='" + textBox2.Text + "'";

                    

 

            da.SelectCommand = cmd;

            da.Fill(ds, "item11");

            DataTable dt11 = ds.Tables["item11"];           

           lpogridview.AutoGenerateColumns = false;

            lpogridview.DataSource =dt1

}


Answers (2)