datagridview values clear

Apr 7 2011 1:55 AM



  i have a form with textbox,button,datagridview. when we click the button ,the database values are inserted into datagridview according to textbox value.  but i have a problem that ,when we click the button 2nd time, first time clicked values are remains in the datagridview,how we clear it?

i use this code

 

private void button1_Click(object sender, EventArgs e)

        {

            displaygrid.DataSource = null;

           cmd.CommandText=   "selectregid,studname,regno,classname,dob,sex,parent,houseno,place1,place2,city,phono,mobno,office,offplace1,offplace2,offcity,offpho,offmob,fax,nationalty,busno from registration r inner join class c on r.classid = c.classid inner join bus b on r.busid = b.busid where r.Studname='" + textBox1.Text + "'";

 

            da.SelectCommand = cmd;

            da.Fill(ds, "name");

            DataTable dt1 = ds.Tables["name"];

            //dt.Clear();

            displaygrid.DataSource = dt1;

        }

 




Answers (2)