求教:.net+access不能实现数据库数据的修改
使用三层体系结构IDAL+DBUTILITY+OLEDBDAL+DALFACTORY+BLL+WEBOleDbDal中 定义了updateUserPassword(int userid, string newpassword)如下
/// <summary>
/// 修改密码
/// </summary>
/// <param name="userid">用户编号</param>
/// <param name="newpassword">新密码</param>
/// <returns></returns>
public int updateUserPassword(int userid, string newpassword)
{
StringBuilder sb = new StringBuilder();
sb.Append(" update userinfo set [password]=@newpassword where [userid]=@userid");
OleDbParameter[] param =
{
OleDbHelper.GetParameter("@userid", OleDbType.Integer, 4, "[userid]", userid) ,
OleDbHelper.GetParameter("@newpassword",OleDbType.Char,50,"[password]",newpassword)
};
return OleDbHelper.ExecuteSql(sb.ToString(), param);
}
调用OleDbHelper类中的
/// <summary>
/// 执行SQL语句
/// </summary>
/// <param name="Sqlstr">SQL语句</param>
/// <param name="param">参数对象数组</param>
/// <returns></returns>
public static int ExecuteSql(String Sqlstr, OleDbParameter[] param)
{
String ConnStr = OleDbHelper.GetSqlConnection();
using (OleDbConnection conn = new OleDbConnection(ConnStr))
{
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = Sqlstr;
cmd.Parameters.AddRange(param);
conn.Open();
try
{
cmd.ExecuteNonQuery();
return 1;
}
catch (System.Data.OleDb.OleDbException ex)
{
return 0;
throw new Exception(ex.Message);
}
finally
{
conn.Close();
}
}
web页实现密码修改按钮点击事件
/// <summary>
/// 修改密码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void updateBt_Click(object sender, EventArgs e)
{
if (user.validUser(user.getUserName(), this.oldpasswordTb.Text.Trim(), 1) == true)
{
if(user.updateUserPassword(user.getUserID(), this.newpasswordTb.Text.Trim())==1)
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('yeal!');</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('旧密码错误!');</script>");
}
}
运行弹出"修改"成功,而查看数据库却发现数据没有改变.什么原因呢?所有修改都似乎有这个问题!!!请帮帮我呀!!急呀!! --------------------编程问答-------------------- updateBt_Click这个方法里面根本就没有去操作数据库啊。 --------------------编程问答-------------------- 没有吗,user.updateUserPassword(user.getUserID(), this.newpasswordTb.Text.Trim())==1着个判断不是吗?
补充:.NET技术 , ASP.NET