Hi,
I am adding a set of data (ex, name, age, mobile etc.) into my database. Whenever I try to enter it the first time its successful. When I try to add after that, I get a constraint exception because I don't change the mobile no which is the primary key. I have written the code in 'try-catch' but I am unable to catch the exception.
public bool Local_LoadData() { using (var db = new SQLite.SQLiteConnection(App._DBPath)) { db.CreateTable<Aadhar_Info>(); try { db.RunInTransaction(() => { db.Insert(new Aadhar_Info() { //1st page data UID = App.UID, FName = App.FName, LName = App.LName, // set UI parameters MName = App.MName, // set UI parameters DateOfBirth = App.UI_DOB, Gender = App.UI_Gender, EmailID = App.EmailID, CareOF = App.CareOF, House = App.House, Street = App.Street, LandMark =App.LandMark, Locality = App.Locality, PostOffice = App.PostOffice, Mobile = App.Mobile, VillageTownCity =App.VillageTownCity, SubDistrict = App.SubDistrict, District = App.District, State = App.State, PinCode = App.PinCode, //2nd page data PAN_GIRNo = App.PAN_GIRNo, MaritialStatus = App.UI_MatitalStatus, Nationality= App.Nationality, ResidentialStatus =App.ResidentialStatus, PermanentAddress1= App.PermanentAddress1, PermanentAddress2= App.PermanentAddress2, PermanentAddress3= App.PermanentAddress3, PermanentAddress4= App.PermanentAddress4, AlternateContactNo=App.AlternateContactNo, OfficeAddress1= App.OfficeAddress1, OfficeAddress2= App.OfficeAddress2, OfficeAddress3=App.OfficeAddress3, OfficeAddress4=App.OfficeAddress4, LandlineNo= App.LandlineNo, ExtensionNo= App.ExtensionNo, Occupation= App.Occupation, Designation= App.Designation }); }); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("tp local Duplicate Entry Restricted"); return false; } }the code crashes within the try and doesnt come into the catch.
I am unable to handle this exception. kindly help.
thanks