public ActionResult Delete(int id)
{
// return to view;
}
public ActionResult Delete(int id)
{
SqlConnection sqlConnection1 = new SqlConnection("server=blahblah");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "exec dbo.spDeleteVehicleAccidentByAccidentId " + "@AccidentId = " + id.ToString();
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
try
{
//Return number of rows
cmd.ExecuteNonQuery();
AddFeedbackMessage("The record has been deleted.");
}
catch (Exception ex) {
Logging.LogError(ex);
}
return RedirectToAction("Search");
}
ALTER PROCEDURE [dbo].[spDeleteVehicleAccidentByAccidentId]
-- Add the parameters for the stored procedure here
@AccidentId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
--BEGIN TRY
--BEGIN TRANSACTION
--Accident Citation
DELETE Accident.tbAccidentCitation
FROM Accident.tbAccidentCitation AS AC
INNER JOIN Accident.tbAccidentDriver AS AD
ON AC.DriverId = AD.Id
WHERE AD.AccidentID = @AccidentID;
--Accident Driver
DELETE Accident.tbAccidentDriver
WHERE AccidentID = @AccidentID;
--other vehicle driver
DELETE Accident.tbAccidentOtherVehicleDriver
FROM Accident.tbAccidentOtherVehicleDriver AS OVD
INNER JOIN Accident.tbAccidentOtherVehicle AS OV
ON OVD.OtherVehicleId = OV.Id
WHERE OV.AccidentID = @AccidentID;
--other vehicle owner
DELETE Accident.tbAccidentOtherVehicleOwner
FROM Accident.tbAccidentOtherVehicleOwner AS OVO
INNER JOIN Accident.tbAccidentOtherVehicle AS OV
ON OVO.OtherVehicleId = OV.Id
WHERE OV.AccidentID = @AccidentID;
--other vehicle insurance
DELETE Accident.tbAccidentOtherVehicleInsurance
FROM Accident.tbAccidentOtherVehicleInsurance AS OVI
INNER JOIN Accident.tbAccidentOtherVehicle AS OV
ON OVI.OtherVehicleId = OV.Id
WHERE OV.AccidentID = @AccidentID;
--other vehicle passenger
DELETE Accident.tbAccidentOtherVehiclePassenger
FROM Accident.tbAccidentOtherVehiclePassenger AS OVP
INNER JOIN Accident.tbAccidentOtherVehicle AS OV
ON OVP.OtherVehicleId = OV.Id
WHERE OV.AccidentID = @AccidentID;
--Adjuster Participant
DELETE Accident.tbAccidentAdjuster
From Accident.tbAccidentAdjuster as AA
Inner Join Accident.tbAccidentParticipant as AP
ON AP.Id = AA.AdjusterParticipantId
WHERE AP.AccidentID = @AccidentID;
--Accident Police
DELETE Accident.tbAccidentPoliceInformation
From Accident.tbAccidentPoliceInformation as API
Inner Join Accident.tbAccidentParticipant as AP
ON AP.Id = API.AuthorityParticipantId
WHERE AP.AccidentID = @AccidentID;
DELETE Accident.tbAccidentUnit
WHERE AccidentID = @AccidentID;
DELETE Accident.tbAccidentTrailer
WHERE AccidentID = @AccidentID;
DELETE Accident.tbAccidentClaimant
FROM Accident.tbAccidentClaimant AS AC
INNER JOIN Accident.tbAccidentParticipant AS AP
ON AC.ClaimantParticipantID = AP.ID
WHERE AP.AccidentID = @AccidentID;
DELETE Accident.tbAccidentParticipant
WHERE AccidentID = @AccidentID;
DELETE Accident.tbAccidentOrderStop
WHERE AccidentID = @AccidentID;
DELETE Accident.tbAccidentPoliceInformation
WHERE AccidentID = @AccidentID;
DELETE Accident.tbAccidentAnalysis
WHERE AccidentID = @AccidentID;
DELETE Accident.tbAccidentCost
WHERE AccidentID = @AccidentID;
DELETE Accident.tbAccidentContributingFactor
WHERE AccidentID = @AccidentID;
DELETE Accident.tbAccidentDiary
WHERE AccidentID = @AccidentID;
--Finally delete the accident record master
DELETE Accident.tbAccident
Where Id = @AccidentId
select @@ROWCOUNT
using (Entities context = new Entities())
{
string ConnectionString = (context.Connection as EntityConnection).StoreCon
SqlConnectionStringBuilder
builder.ConnectTimeout = 2500;
SqlConnection con = new SqlConnection(builder.Conn
System.Data.Common.DbDataR
con.Open();
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "GetEmployeeData";
cmd.CommandType = System.Data.CommandType.St
cmd.CommandTimeout = 0;
sqlReader = (System.Data.Common.DbData
IEnumerable<EmployeeDetail
}
}
HTH
Ashok