kwh3856
asked on
Try Catch (Exception e) 'e' cannot be decalred in this scope because it would give a different meaning to 'e'
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
{
// --
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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();
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.
"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.
ASKER
ok i will try - I did not notice it was only a warning.
have you uses x in catch yet?
for ex.
System.Console.WriteLine(" Error message : " + x.Message);
for ex.
System.Console.WriteLine("
ASKER
Thank you. That was exactly it.
ASKER
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