应用存储过程删除数据

 

Default.aspx

View Code
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>无标题页</title>
</head>
<body style="font-size: 12px">
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
            ForeColor="#333333" GridLines="None" OnRowDeleting="GridView1_RowDeleting" Style="border-right: #cccccc thin groove;
            border-top: #cccccc thin groove; border-left: #cccccc thin groove; border-bottom: #cccccc thin groove"
            Width="375px">
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <Columns>
                <asp:BoundField DataField="员工编号" HeaderText="员工编号" />
                <asp:BoundField DataField="员工姓名" HeaderText="员工姓名" />
                <asp:BoundField DataField="身份证号" HeaderText="身份证号" />
                <asp:BoundField DataField="联系电话" HeaderText="联系电话" />
                <asp:CommandField ShowDeleteButton="True" />
            </Columns>
            <RowStyle BackColor="#E3EAEB" />
            <EditRowStyle BackColor="#7C6F57" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
    
    </div>
    </form>
</body>
</html>

Default.aspx.cs

View Code
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Data.SqlClient;

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

    protected void Page_Load(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);
        SqlDataAdapter dap = new SqlDataAdapter("select * from 员工信息表", con);
        DataSet ds = new DataSet();
        dap.Fill(ds, "table");
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "员工编号" };
        GridView1.DataBind();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);//创建数据库连接
        con.Open();//打开数据库
        SqlCommand cmd = new SqlCommand("procDeleteEmployee", con);//调用执行删除的存储过程
        cmd.CommandType = CommandType.StoredProcedure;//设定数据操作类型
        SqlParameter pares = new SqlParameter("@员工编号", SqlDbType.VarChar, 50);
        cmd.Parameters.Add(pares);//添加参数
        cmd.Parameters["@员工编号"].Value = GridView1.DataKeys[e.RowIndex].Value.ToString();//传值操作
        cmd.ExecuteNonQuery();//执行删除操作
        con.Close();//关闭连接
        this.Page_Load(sender, e);
    }
}

 

转载于:https://www.cnblogs.com/hsw-2013/archive/2013/03/21/2972473.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值