我有以下代码来设置页面加载时的文本框值。
protected void Page_Load(object sender, EventArgs e)
{
localhost.UserRegistration m = new localhost.UserRegistration();
int user = m.ID(Session["Username"].ToString());
DataSet ds = m.GetUserInfo(user);
if (ds.Tables.Count > 0)
{
TextBox1.Text = ds.Tables[0].Rows[0]["emailAddress"].ToString();
TextBox2.Text = ds.Tables[0].Rows[0]["password"].ToString();
}
}
因此,当第一个用户打开页面时,用户将在文本框中看到他们的电子邮件地址和密码。当他们进行更改并单击更新时,页面加载时的相同值将被发送到数据库,而不是被更改的新值。
我有以下 Web 服务方法来更新用户详细信息
[WebMethod(Description = "Updates a single user")]
public string UpdateUser(int user, string emailAddress, string password)
{
// Create connection object
int ix = 0;
string rTurn = "";
OleDbConnection oleConn = new OleDbConnection(connString);
try
{
oleConn.Open();
string sql = "UPDATE [User] SET [emailAddress]=@emailAddress, [password]=@password" + " WHERE [ID]=@user";
OleDbCommand oleComm = new OleDbCommand(sql, oleConn);
oleComm.Parameters.Add("@user", OleDbType.Integer).Value = user;
oleComm.Parameters.Add("@emailAddress", OleDbType.Char).Value = emailAddress;
oleComm.Parameters.Add("@password", OleDbType.Char).Value = password;
ix = oleComm.ExecuteNonQuery();
if (ix > 0)
rTurn = "User Updated";
else
rTurn = "Update Failed";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
rTurn = ex.ToString();
}
finally
{
oleConn.Close();
}
return rTurn;
}
这是表在数据库中的外观
客户端代码
protected void Button1_Click(object sender, EventArgs e)
{
string email = TextBox1.Text;
string pass = TextBox2.Text;
localhost.UserRegistration m = new localhost.UserRegistration();
int usr = m.ID(Session["Username"].ToString());
m.UpdateUser(usr, email, pass);
}
谁能告诉我为什么....