62,047
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class EditUser : System.Web.UI.Page
{
private int nUserID = -1;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Params["UserID"] != null)
{
if (int.TryParse(Request.Params["UserID"].ToString(), out nUserID) == false)
{
return;
}
}
if (!Page.IsPostBack)
{
if (nUserID > -1)
{
User user = new User();
SqlDataReader dr = user.GetSingleUser(nUserID);
if (dr.Read())
{
UserName.Text = dr["UserName"].ToString();
Email.Text = dr["Email"].ToString();
}
dr.Close();
}
}
}
protected void ModifyBtn_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
User user=new User();
try
{
user.UpdateUser(nUserID,Email.Text.Trim());
Response.Write("<script>alert('更新数据成功,请妥善保管好您的信息!')</script>");
}
catch (Exception ex)
{
Response.Redirect("~/Error.aspx?ErrorMsg="+ex.Message+"&ErrorUrl="+Request.Url.ToString());
}
}
}
protected void ReturnBtn_Click(object sender, EventArgs e)
{
Response.Redirect("~/UserManage.aspx");
}
}
public int UpdateUser(int nUserID, string sEmail)
{
SqlConnection con = DB.createDB();
string cmdText = UPDATEUSER + "'" + sEmail + "'" + "where UserID=" + "'" + nUserID.ToString() + "'";
SqlCommand cmd = new SqlCommand(cmdText, con);
int nResult = -1;
try
{
con.Open();
nResult = cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
throw new Exception(ex.Message, ex);
}
finally
{
con.Close();
}
return nResult;
}
create table Users
(
UserID int identity primary key,
UserName varchar(50),
Password varchar(100),
Email varchar(200),
IsAdmin bit
)
if (Request.Params["UserID"] != null)
{
if (int.TryParse(Request.Params["UserID"].ToString(), out nUserID) == false)
{
return;
}
}