How to continue to next block of code...

I have the following block of code:
 
string createString = "CREATE TABLE tAZUID (MWSMerchantID VARCHAR (25), MWSMarketplaceID VARCHAR (25), " +
                "AWSAccessKey VARCHAR (25), AWSSecretKey VARCHAR (50), AWSAssocTag VARCHAR (15))";
            sqlCmd = new FbCommand(createString, maintenanceConn);
            try {
                sqlCmd.ExecuteNonQuery();
            }
            catch (Exception e) {
                if (e.Message.Contains("Table TAZUID already exists"))
                    return;
                else
                    MessageBox.Show("Error creating tAZUID: " + e.Message, "Prager, Media Inventory Program", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //  now, grant permissions
            string grantPermissions = "GRANT ALL ON tAZUID TO PUBLIC";
            sqlCmd = new FbCommand(grantPermissions, maintenanceConn);
            try {
                sqlCmd.ExecuteNonQuery();
            }
            catch (Exception e) {
                MessageBox.Show("Error creating permissions for tAZUID: " + e.Message, "Prager, Media Inventory Program", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

Open in new window


In the above code, if the table already exists, I don't want to execute the code granting permissions.  However, following that code, I have this:
 
createString = "CREATE TABLE tCannedText (sTitle VARCHAR (20), sCannedText VARCHAR (200))";
            sqlCmd = new FbCommand(createString, maintenanceConn);
            try {
                sqlCmd.ExecuteNonQuery();
            }
            catch (Exception e) {
                if (e.Message.Contains("Table tCannedText already exists"))
                    return;
                else
                    MessageBox.Show("Error creating tCannedText: " + e.Message, "Prager, Media Inventory Program", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //  now, grant permissions
            grantPermissions = "GRANT ALL ON tCannedText TO PUBLIC";
            sqlCmd = new FbCommand(grantPermissions, maintenanceConn);
            try {
                sqlCmd.ExecuteNonQuery();
            }
            catch (Exception e) {
                MessageBox.Show("Error creating permissions for tCannedText: " + e.Message, "Prager, Media Inventory Program", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

Open in new window


which I want to execute regardless of the outcome of the first block of code.  Is there a clean way of accomplishing this without a 'GOTO"?
rmmarshAsked:
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.

Miguel OzSoftware EngineerCommented:
Just create a local variable to keep track of table:
bool isTazuidExist = false;

First block replace lines 7 -12 with:
catch (Exception e) {
                if (e.Message.Contains("Table TAZUID already exists"))
                    isTazuidExist = true;
                else
                    MessageBox.Show("Error creating tAZUID: " + e.Message, "Prager, Media Inventory Program", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

then on every piece of code that you do not need to be executed add:
if (!isTazuidExist)
{
 //Your code here (e.g lines 14-22)
}
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
rmmarshAuthor Commented:
I had already thought of that... thought there might be a more "elegant" way of doing it! :D

Thank you.  Happy New Year!
0
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
.NET Programming

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.