C# SqlDataAdapter commands get deleted after reading a table


In my application, i'm trying to create an SqlDataAdapter that i can reuse later.  All what i would have to do is change a parameter like this (mAdapZones.SelectCommand.Parameters["@MyParam"].Value = SomeValue) and call the Fill method to get an update, but i have a strange behavior.   As soon as the program hit the line where i assign the datasource of the gridZones, when i run the program step by step, i see that all the commands (SelectCommand, InsertCommand and DeleteCommands) get nullified.

            mAdapZones.SelectCommand.Parameters["@CustPartCustID"].Value = wCustID.ToString();
            mDSZones = new System.Data.DataSet();
            mAdapZones.Fill(mDSZones, "Zones");
            gridZones.DataSource = mDSZones.Tables[0];

Open in new window

Is this a normal behavior?  Is there any way i can keep the SqlDataAdapter for later use?

Thank you
LVL 10
Christian de BellefeuilleProgrammerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

John Gates, CISSPSecurity ProfessionalCommented:
What you have posted is not giving enough information to assist...  I normally code all my CRUD operations Create Read Update and Delete into modules that can be called and the SQL etc is built dynamically.  Can you post more code so that I can give a recommendation?


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
Christian de BellefeuilleProgrammerAuthor Commented:
Sorry it took some time for me to answer.  I did a test program with only few lines of codes, and i was not able to reproduce the problem in it so i had to dig it a little bit myself.  I've found out my mistake.  I was calling dispose in a method that was not supposed to be called.
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

From novice to tech pro — start learning today.