Refresh datagridview after db update

Alrighty I update, and delete in my acess db.  However after doing that I hit my button to search again and its adding the results to the bottom of my previous results instead of getting rid of old ones and then putting in new ones.  any ideas?
                OdbcConnection con = new OdbcConnection("DSN=ShipData");
                OdbcDataAdapter da = new OdbcDataAdapter();
                DataTable dt = new DataTable();
                string sqlQuery = "SELECT * FROM Address Order by Code";
                OdbcCommand com = new OdbcCommand(sqlQuery, con);
                da.SelectCommand = com;
                OdbcCommandBuilder cmbuilder = new OdbcCommandBuilder(da);
                cmbuilder.QuotePrefix = "[";
                cmbuilder.QuoteSuffix = "]";
                da.Fill(dt);
                dataGridView1.DataSource = dt;

Open in new window

casitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pratima PharandeCommented:
You mean to say you want direct reresh after update and delete without using busston clik ?

Then do one this put above acode in one function..

and call that function after update and delete
0
aherpsCommented:
Clear the table first on button click:

dataGridView1.Rows.Clear();

before adding doing the SELECT command
0
casitAuthor Commented:
When I put rows.clear in I get the following exception report
System.ArgumentException was unhandled
  Message="Cannot clear this list."
  Source="System.Data"
  StackTrace:
       at System.Data.DataView.System.Collections.IList.Clear()
       at System.Windows.Forms.DataGridViewRowCollection.Clear()
       at FedEx_Shared_Addy.frmSharedAddy.loadAllAddresssToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\chris\Documents\Visual Studio 2005\Projects\FedEx Shared Addy\Form1.cs:line 62
       at FedEx_Shared_Addy.frmSharedAddy.Loadalldata_Click(Object sender, EventArgs e) in C:\Users\chris\Documents\Visual Studio 2005\Projects\FedEx Shared Addy\Form1.cs:line 83
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at FedEx_Shared_Addy.Program.Main() in C:\Users\chris\Documents\Visual Studio 2005\Projects\FedEx Shared Addy\Program.cs:line 17
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

Open in new window

0
casitAuthor Commented:
nm I figured it out.  I had to first clear my datatable and then everything was good.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.