C# asp - How to set button delete from database

2236 views sql
0

this is the behind code :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication9.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
        </div>
        <p>
            ID
            <asp:TextBox ID="id" runat="server"></asp:TextBox>
        </p>
        <p>
            Name
            <asp:TextBox ID="name" runat="server"></asp:TextBox>
        </p>
        <p>
            Email
            <asp:TextBox ID="email" runat="server"></asp:TextBox>
        </p>
        <p>
            Mobile
            <asp:TextBox ID="mobile" runat="server"></asp:TextBox>
        </p>
        <p>
            Date
            <asp:TextBox ID="date" runat="server" TextMode="Date"></asp:TextBox>
        </p>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click"  Text="insert" />
&nbsp;<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Delete" />
&nbsp;<br />
        <br />


    </form>

</body>
</html>

i want query sql that help me to delete what user inserted in the same time , i mean when user insert data and click submit it will save on my database its work , when user click delete its not delete the row why ?

this is procedures code in sql server fro my database:

USE [MohDB]
GO
/****** Object:  StoredProcedure [dbo].[Empdel]    Script Date: 11/5/2018 1:03:14 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[Empdel]


@a int,
@b nvarchar(50),
@c nvarchar(50),
@d nvarchar (50),
@e date


AS
BEGIN

DELETE FROM [dbo].[EmpTbl]
      WHERE EmpID=6;


END

answered question

1 Answer

8

You are not setting parameter to your delete call in your procedure. Your Procedure is setup with default value of 6. It should be like this

ALTER PROCEDURE [dbo].[Empdel]


@a int,
@b nvarchar(50),
@c nvarchar(50),
@d nvarchar (50),
@e date


AS
BEGIN

DELETE FROM [dbo].[EmpTbl]
      WHERE EmpID=@a;


END

posted this

Have an answer?

JD

Please login first before posting an answer.