We help IT Professionals succeed at work.
Get Started

How to clear a datagridview

ANINDYA
ANINDYA asked
on
457 Views
Last Modified: 2013-12-17
Experts
I have a datagridview which is displaying data already by the following code.

private void show_valueInDGVItems()
        {
            Int32 CustomerID;
            CustomerID = Convert.ToInt32(label_Custmer_ID.Text);
            string query3 = "select * from Table_InvoiceItem WHERE CustomerID=@parameter1";
            using (SqlConnection con3 = new SqlConnection("Data source=INVENTOR-6FBADA\\SQLEXPRESS;Initial Catalog=AnindyaCD;Integrated Security=SSPI"))
            {
                using (SqlCommand cmd3 = new SqlCommand(query3, con3))
                {
                    cmd3.Parameters.AddWithValue("@parameter1", CustomerID);
                    using (SqlDataAdapter ad = new SqlDataAdapter(query3, con3))
                    {
                        ad.SelectCommand = cmd3;
                        DataSet ds = new DataSet();
                        ad.Fill(ds, "Table_InvoiceItem");
                        dataGridView_showItemtoSell.DataSource = ds.Tables[0];
                    }
                }
            }
        }
Now my question is how to clear the datagridview by a checkbox event of checkchanged.
private void show_valueInDGVItems()
        {
            Int32 CustomerID;
            CustomerID = Convert.ToInt32(label_Custmer_ID.Text);
            string query3 = "select * from Table_InvoiceItem WHERE CustomerID=@parameter1";
            using (SqlConnection con3 = new SqlConnection("Data source=INVENTOR-6FBADA\\SQLEXPRESS;Initial Catalog=AnindyaCD;Integrated Security=SSPI"))
            {
                using (SqlCommand cmd3 = new SqlCommand(query3, con3))
                {
                    cmd3.Parameters.AddWithValue("@parameter1", CustomerID);
                    using (SqlDataAdapter ad = new SqlDataAdapter(query3, con3))
                    {
                        ad.SelectCommand = cmd3;
                        DataSet ds = new DataSet();
                        ad.Fill(ds, "Table_InvoiceItem");
                        dataGridView_showItemtoSell.DataSource = ds.Tables[0];
                    }
                }
            }
        }

Open in new window

Comment
Watch Question
Staff Software Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 16 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE