Solved

Try Catch (Exception e) 'e' cannot be decalred in this scope because it would give a different meaning to 'e'

Posted on 2011-03-23
7
558 Views
Last Modified: 2013-12-17
I am trying to delete a record using LINQ and then submit the changes in a Try/Catch statement but it will not let me trap for errors.  Can someone tell me what I am missing.   Here is my code:


DataClasses1DataContext dcDataClass1 = new DataClasses1DataContext();


            PatientMed myPatientMed = new PatientMed();

            MyGlobalVars.DeleteRecordKey = this.UltraWebGridSelectedMeds.DisplayLayout.SelectedRows[0].Cells.FromKey("PatMedsKey").Text;

            var SelectedMedsResult = from selectedmedsdata in dcDataClass1.PatientMeds
                                     where selectedmedsdata.PatMedsKey.ToString() == MyGlobalVars.DeleteRecordKey
                                     select selectedmedsdata;


            foreach (var selectedmedsresultrecord in SelectedMedsResult)
            {
                

                dcDataClass1.PatientMeds.DeleteOnSubmit(selectedmedsresultrecord);

                try
                {
                    dcDataClass1.SubmitChanges();

                }
                catch (Exception e)  <<<  ------------ error occurs here
                {
                    // --
                }

Open in new window

0
Comment
Question by:kwh3856
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 

Author Comment

by:kwh3856
ID: 35203780
Actual error message:

Error 1 A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e', which is already used in a 'parent or current' scope to denote something else      
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 35203791
Most likely the EVENT that this code is in has a PARAMETER that is called "e".

All you need to do is change the name of your Exception variable in the Catch block to something else.

Change:

                catch (Exception e)  
                {
                    // --
                }

To:

                catch (Exception e2)  
                {
                    // ... use "e2" in here ...
                }
0
 

Author Comment

by:kwh3856
ID: 35203792
I think it may be referring to the following code but still not sure how to correct it.  Tried to change it to (Exception x) but then got the error "The variable 'x' is declared but never used"



protected void UltraWebGridSelectedMeds_SelectedRowsChange(object sender, SelectedRowsEventArgs e)
        {

            DataClasses1DataContext dcDataClass1 = new DataClasses1DataContext();

Open in new window

0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35203798
This is simply a WARNING:

    "The variable 'x' is declared but never used"

that means you are not using the 'x' variable anywhere in the Catch{} block.  It should still compile and run fine.
0
 

Author Comment

by:kwh3856
ID: 35203803
ok i will try - I did not notice it was only a warning.
0
 
LVL 11

Expert Comment

by:JoeNuvo
ID: 35203805
have you uses x in catch yet?

for ex.

System.Console.WriteLine("Error message : " + x.Message);
0
 

Author Closing Comment

by:kwh3856
ID: 35203853
Thank you.  That was exactly it.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question