Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
void gridshw2()
    {
        cn.Open();
        s = "Select * from persn_info";
        try
        {
            da = new OleDbDataAdapter(s, cn);
            DataSet ds = new DataSet();
            da.Fill(ds, "set");
            dataGridView2.DataSource = ds;
            dataGridView2.DataMember = "set";

            s = "select sub_no from paymnt_info";
            cm = new OleDbCommand(s, cn);
            rd = cm.ExecuteReader();
            if (rd.Read())
            {

                    if (rd["sub_no"].ToString() == dataGridView2.Rows[].Cells[0].Value.ToString())
                    {
                        dataGridView2.Rows.RemoveAt(0);
                    }

            }
        }
        catch (Exception ea)
        {
            MessageBox.Show(ea.Message);
        }
        finally {
            cn.Close();
        }
    }
Posted
Comments
Kumarbs 31-Jul-14 5:33am    
You used the code "dataGridView2.Rows.RemoveAt(0);", it only deletes the first record. Try to remove by looping the records.

1 solution

You can use blank ("") DataSource and bind to gridview. It will do clear whole gridview. So you don't need to remove individual rows.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900