表为User,字段有 编号: int id,用户名:string UserName,密码:string UserPwd
  /// <summary>
    /// 添加     
    /// </summary>
    /// <param name="name">用户名</param>
    /// <param name="pwd">密码</param>
    /// <returns></returns>
    [WebMethod]
    public int Add(string name,string pwd)
    {
        SqlConnection conn = new SqlConnection("连接字符串");
        conn.Open();
        string sql = "intsert into User (UserName,UsersPwd) values(@UserName,@UsersPwd)";
        SqlCommand cmd = new SqlCommand(sql, conn);
        SqlParameter parn = new SqlParameter("@UserName", name);
        cmd.Parameters.Add(parn);
        SqlParameter parp = new SqlParameter("@UsersPwd", pwd);
        cmd.Parameters.Add(parp);
        int result = cmd.ExecuteNonQuery();
        conn.Close();
        cmd.Dispose();
        return result;
    }
    /// <summary>
    /// 修改
    /// </summary>
    /// <param name="name">用户名</param>
    /// <param name="pwd">密码</param>
    /// <param name="id">编号</param>
    /// <returns></returns>
    [WebMethod]
    public int Update(string name, string pwd, int id)
    {
        SqlConnection conn = new SqlConnection("连接字符串");
        conn.Open();webservice用户名密码调用
        string sql = "update User set UserName=@UserName,UsersPwd=@UsersPwd where id=@id";
        SqlCommand cmd = new SqlCommand(sql, conn);
        SqlParameter parn = new SqlParameter("@UserName", name);
        cmd.Parameters.Add(parn);
        SqlParameter parp = new SqlParameter("@UsersPwd", pwd);
        cmd.Parameters.Add(parp);
        SqlParameter pari = new SqlParameter("@id", id);
        cmd.Parameters.Add(pari);
        int result = cmd.ExecuteNonQuery();
        conn.Close();
        cmd.Dispose();
        return result;
    }
    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="id">编号</param>
    /// <returns></returns>
    [WebMethod]
    public int Delete(int id)
    {
        SqlConnection conn = new SqlConnection("连接字符串");
        conn.Open();
        string sql = "delete from User where id=@id";
        SqlCommand cmd = new SqlCommand(sql, conn);       
        SqlParameter pari = new SqlParameter("@id", id);
        cmd.Parameters.Add(pari);
        int result = cmd.ExecuteNonQuery();
        conn.Close();
        cmd.Dispose();
        return result;
    }

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。