添加管理员.aspx.cs

(完整代码) 1KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class 添加管理员 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btGuanli_Click(object sender, EventArgs e)
    {
        con.ConnectionString = "Data Source=localhost;Initial Catalog=招聘网站;Integrated Security=True;";
        SqlDataAdapter da = new SqlDataAdapter("select * from 管理员表 ", con);
        DataSet ds = new DataSet();
        da.Fill(ds, "管理员表");

        SqlDataAdapter da1 = new SqlDataAdapter("select * from 管理员表 where 登录名='"+txtName.Text.Trim()+"'", con);
        DataSet ds1 = new DataSet();
        da1.Fill(ds1, "管理员表1");
        if (ds1.Tables["管理员表1"].Rows.Count == 0)
        {
            DataRow dr = ds.Tables["管理员表"].NewRow();
            dr["登录名"] = txtName.Text.Trim();
            dr["密码"] = txtPass.Text.Trim();
            dr["权限"] = "管理员";
            ds.Tables["管理员表"].Rows.Add(dr);
            SqlCommandBuilder cbd = new SqlCommandBuilder(da);
            da.Update(ds, "管理员表");
            ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('管理员添加成功!');</script>");
        }
        else
            ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('该管理员已存在,请重新添加!');</script>");

    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读 AI

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。