Click here to Skip to main content
16,016,477 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
I am fetching the problem with deleteing the record from multiple tables,
When I m trying to delete the record its ocours the exception
CSS
ArgumentNullExceptioncan not be handeled by user.
Value cannot be null.
Parameter name: entity


Code :

C#
       [NonAction]
private FinancilInstituteWrappergetData(int id)
        {
FinancilInstituteWrapper temp = newFinancilInstituteWrapper();
var details = from i indb.IIDBS
join a indb.ACDBS
oni.Idequalsa.Id
join b indb.BIDBSoni.Idequalsb.Id
wherei.Id==id
selectnewFinancilInstituteWrapper
                          {
                              II = i,
                              AC = a,
                              BI = b
                          };
foreach (FinancilInstituteWrapper a in details)
            {
temp.II = a.II;
                temp.BI = a.BI;
                temp.AC = a.AC;
            }

return temp;
        }

//
// GET: /FinancilInstitute/Delete/5
publicActionResult Delete(int id=0)
        {
return View(getData(id));
        }

//
// POST: /FinancilInstitute/Delete/5

        [HttpPost,ActionName("Delete")]
publicActionResultDeleteConfirmed(int id = 0)
        {
FinancilInstituteWrapper wrapper = newFinancilInstituteWrapper();         
db.IIDBS.Remove(wrapper.II);
db.ACDBS.Remove(wrapper.AC);
db.BIDBS.Remove(wrapper.BI);
db.SaveChanges();
returnRedirectToAction("Index");           
        }


View:
<%@PageTitle=""Language="C#"MasterPageFile="~/Views/Shared/Site.Master"Inherits="System.Web.Mvc.ViewPage<BachatGatProjectFinal.Controllers.FinancilInstituteWrapper>"%>

<h2>Delete</h2>

<h3>Are you sure you want to delete this?</h3>
<fieldset>
<legend>FinancilInstituteWrapper</legend>

<div>
<%:Html.HiddenFor(m=>m.II.Id) %>
</div>

<div>
        Institute Name
<%:Html.DisplayFor(m=>m.II.InstituteName) %>
</div>

<div>
        Owners First Name
<%:Html.DisplayFor(m=>m.II.OwnersFirstName) %>
</div>

<div>
        Owners Last Name
<%:Html.DisplayFor(m=>m.II.OwnersLastName) %>
</div>

<div>
<%:Html.HiddenFor(m=>m.AC.Id) %>
</div>

<div>
        Address
<%:Html.DisplayFor(m=>m.AC.Address) %>
</div>

<div>
        City
<%:Html.DisplayFor(m=>m.AC.City) %>
</div>

<div>
        State
<%:Html.DisplayFor(m=>m.AC.State) %>
</div>

<div>
PinCode
<%:Html.DisplayFor(m=>m.AC.PinCode) %>
</div>

<div>
        Phone
<%:Html.DisplayFor(m=>m.AC.Phone) %>
</div>

<div>
        Email
<%:Html.DisplayFor(m=>m.AC.Email) %>
</div>

<div>
<%:Html.HiddenFor(m=>m.BI.Id) %>
</div>

<div>
BankName
<%:Html.DisplayFor(m=>m.BI.BankName) %>
</div>

<div>
        Branch
<%:Html.DisplayFor(m=>m.BI.Branch) %>
</div>

<div>
        Account Number
<%:Html.DisplayFor(m=>m.BI.AccountNumber) %>
</div>

<div>
        MICR
<%:Html.DisplayFor(m=>m.BI.MICR) %>
</div>

<div>
        IFSC
<%:Html.DisplayFor(m=>m.BI.IFSC) %>
</div>
</fieldset>
<%using (Html.BeginForm()) { %>
<p>
<inputtype="submit"value="Delete"/> |
<%:Html.ActionLink("Back to List", "Index") %>
</p>
<% } %>


Pls help
Posted
Updated 15-Apr-14 0:32am
v3

kindly first check the complete process whether is there any null value going into the data base
 
Share this answer
 
Your exception may be thrown due to below line.So check the null-ability of that entity (i.e. indb.BIDBSoni.Idequalsb != null ) before do the join.

SQL
join b indb.BIDBSoni.Idequalsb.Id
where i.Id==id
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900