troubleshooting Question

Can't clear a DataGridView before Insert method is called to refresh the screen...

Avatar of Saxitalis
Saxitalis asked on
.NET Programming
5 Comments1 Solution800 ViewsLast Modified:
Hi,
Does anyone know how to clear a DaGridView control?

I am binging a DataGridView control in the Load method of a windows form. I then change some data and call an Update method. The data updates but the DataGridView dosn't reflect the changes unless I open and close the form.

Is there a way to refresh the screen without having to open and reclose??

 Refresh() doesn't seem to work.

My Code:

When Form Loads:
Conn = new OleDbConnection(ConStr))
 cmd = new OleDbCommand(SQL, Conn))
 Conn.Open();
 da = new OleDbDataAdapter())
 da.SelectCommand = cmd;
 oleDbCb = new OleDbCommandBuilder(da))
da.Fill(dataSet1, "Stats");
dataGridView1.DataSource = dataSet1;
dataGridView1.DataMember = "Stats";

Insert Method:
string connectionString = LoginFirst.Connection;
                OleDbConnection connection = new OleDbConnection(connectionString);
                connection.Open();
                OleDbCommand command = new OleDbCommand();
                command.Connection = connection;
                command.CommandText = "spInsertTrawlT";
                command.CommandType = CommandType.StoredProcedure;
                OleDbDataReader dr = command.ExecuteReader();
                da.InsertCommand = command;
                connection.Close();

If I call the load method after the Insert method, the DataGridView fills agin but rows are doubled. Is there a method to clear the DataGridView before reloading it??
ASKER CERTIFIED SOLUTION
Justin_W

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros