Click here to Skip to main content
15,888,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Code:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_driverdetails : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            pnlControls.Visible = true;
            pnlGrid.Visible = false;
        }
    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        DriverInfo driver = new DriverInfo();
        driver.DriverName = txtDriverName.Text;
        driver.Mobile = txtMobile.Text;
        driver.Email = txtEmail.Text;
        driver.LNo = txtLNo.Text;
        driver.LExpDate = DateTime.Parse(txtLExpDate.Text);
        driver.BloodGroup = txtBlood.Text;
        driver.Address = txtAddress.Text;
        driver.DOB = dtpDOB.Text;
        driver.Insert();


    }

    protected void lnkEdit_Click(object sender, EventArgs e)
    {
        pnlControls.Visible = !pnlControls.Visible;
        pnlGrid.Visible = !pnlControls.Visible; ;

        if (pnlControls.Visible)
        {
            lnkEdit.Text = "View / Edit Driver";
        }
        else
        {
            lnkEdit.Text = "Add New Driver";
            LoadDrivers();
        }

    }

    private void LoadDrivers()
    {
        DriverInfo drivers = new DriverInfo();
        var op = drivers.GetAll();
        rptPast.DataSource = op;
        rptPast.DataBind();


    }







    protected void lnkbutEdit_Click(object sender, EventArgs e)
    {
        pnlControls.Visible = !pnlControls.Visible;
        pnlGrid.Visible = !pnlControls.Visible; ;
        var driverId = ((LinkButton)sender).CommandArgument;
        if (pnlControls.Visible)
        {
            lnkEdit.Text = "View / Edit Driver";

            LoadControls(driverId);
        }
        else
        {
            lnkEdit.Text = "Add New Driver";

        }
    }


    private void LoadControls(string driverId)
    {
        DriverInfo drivers = new DriverInfo();
        drivers.DriverId = long.Parse(driverId);
        var op = drivers.Get();


        txtAddress.Text = op.Address;
        txtDriverName.Text = op.DriverName;
        txtMobile.Text = op.Mobile;
        txtEmail.Text = op.Email;
        txtLNo.Text = op.LNo;
        txtBlood.Text = op.BloodGroup;
        dtpDOB.Text = op.DOB;



    }



    protected void lnkbutDelete_Click(object sender, EventArgs e)
    {
        {
            
            var driverId = ((LinkButton)sender).CommandArgument;
           
                LoadDelControls(driverId);
           
        }
    }

    private void LoadDelControls(string driverId)
    {
        DriverInfo drivers = new DriverInfo();
        drivers.DriverId = long.Parse(driverId);
        var op = drivers.Delete();
       
    
        
      
    }


    }






class file:
C#
public bool Delete()
   {
       var obj = new DbHelp(spName);
       obj.AddInParameter("@DriverId", DriverId);
       obj.AddInParameter("@mode", "delete");
       var dt = obj.ExecuteNonQuery();
       return dt > 0;
   }
Posted
Updated 25-Jan-16 0:34am
v2

1 solution

Does the records get deleted from the database?
Is dt returning correctly (True when deleted)?

If dt is not returning the cirrect value then I would change the stored proc to return the number of records delete (should be 1).
Use ExecuteScalar instead of ExcecuteNonQuery and get the return value
Check that the return value is > 0 and remove the record from your collection.

If it is returning the correct value then check the value of dt and remove the item from your collection.

You are missing the last step!
 
Share this answer
 
Comments
Member 12081616 25-Jan-16 4:25am    
Thanks..but i changed ExcecuteNonQuery to ExecuteSaclar ,its again showing error..
wht is the last step??
i dint get properly
Member 12081616 25-Jan-16 4:26am    
this my stored proc:
USE [rttrack]
GO
/****** Object: StoredProcedure [dbo].[sp_DriverInfo] Script Date: 25-Jan-16 1:21:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_DriverInfo] @DriverName NVARCHAR(50)=NULL,
@Mobile NVARCHAR(50)=NULL,
@Email NVARCHAR(50)=NULL,
@DOB NVARCHAR(50)=NULL,
@BloodGroup NVARCHAR(50)=NULL,
@LNo NVARCHAR(50)=NULL,
@LExpDate DATETIME=NULL,
@Address NVARCHAR(200)=NULL,
@DriverId BIGINT=NULL,
@mode NVARCHAR(50)
AS

BEGIN
IF(@mode = 'insert')
BEGIN
INSERT INTO tbl_DriverInfo ( DriverName,
Mobile,
Email,
DOB,
BloodGroup,
LNo,
LExpDate,
Address)
output inserted.DriverId
VALUES
( @DriverName,
@Mobile,
@Email,
@DOB,
@BloodGroup,
@LNo,
@LExpDate,
@Address)
END
IF(@mode = 'update')
BEGIN
UPDATE tbl_DriverInfo
set
DriverName = Isnull(@DriverName, DriverName),
Mobile = Isnull(@Mobile, Mobile),
Email = Isnull(@Email, Email),
DOB = Isnull(@DOB, DOB),
BloodGroup = Isnull(@BloodGroup, BloodGroup),
LNo = Isnull(@LNo, LNo),
LExpDate = Isnull(@LExpDate, LExpDate),
Address = Isnull(@Address, Address)
where DriverId=@DriverId
END

IF(@mode = 'get' )
BEGIN
select * from tbl_DriverInfo

where DriverId=@DriverId
END

IF(@mode = 'getall' )
BEGIN
select * from tbl_DriverInfo
END


IF( @mode = 'delete')
BEGIN
Update tbl_DriverInfo
set IsDeleted = 1
Where DriverId=@DriverId
END

END
Mycroft Holmes 25-Jan-16 7:59am    
Okay you have more problems that you think.
Split that proc into 3
Select - return 1 or all (if driverid = 0 then return all)
Update inserts or updates (if driverid = 0 insert) and returns the changed record
Delete returns the @@ROWCOUNT after delete or the changed record.

Your current proc cannot meet your business requirements.

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