.net执行修改,获得受影响行数为1,可是数据库内容却没有改变
执行修改,获得受影响行数为1,可是数据库内容却没有改变。
DAL层SqlHelper类代码。
public int executeUpdate(string sql, SqlParameter[] param)
{
int count = 0;
SqlConnection conn = new SqlConnection(ConnectionString);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
if (param != null)
{
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
}
count = cmd.ExecuteNonQuery();
}
catch (FormatException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
return count;
}
DAL层修改信息方法代码
public int UpdateStuInfo(Student student)
{
string sql = null;
SqlParameter[] param = null;
try
{
sql = "update student set sName=@sName,sSex=@sSex,sClass=@sClass,sPhone=@sPhone "
+ "where sNO=@sNO";
param = new SqlParameter[5];
param[0] = new SqlParameter("@sName", SqlDbType.VarChar, 20);
param[0].Value = student.SName;
param[1] = new SqlParameter("@sSex", SqlDbType.VarChar, 2);
param[1].Value = student.SSex;
param[2] = new SqlParameter("@sclass", SqlDbType.VarChar, 20);
param[2].Value = student.SClass;
param[3] = new SqlParameter("@sPhone", SqlDbType.VarChar, 20);
param[3].Value = student.SPhone;
param[4] = new SqlParameter("@sNO", SqlDbType.VarChar, 20);
param[4].Value = student.SNO;
return sqlHelper.executeUpdate(sql, param);
}
catch (FormatException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
}
BLL层修改代码
public bool UpdateStuInfo(Student student)
{
int num = 0;
try
{
num = stuService.UpdateStuInfo(student);
if (num > 0)
{
return true;
}
else
{
return false;
}
}
catch (FormatException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
}
前台页面代码
student.SName = txtUpdateName.Text;
if (rdoUpdateMan.Checked == true)
{
student.SSex = "男";
}
else
{
student.SSex = "女";
}
student.SClass = txtUpdateOffice.Text;
student.SPhone = txtUpdatePhone.Text;
student.SNO = txtUpdateNO.Text;
bool IsUpdate = false;
try
{
IsUpdate = stuManager.UpdateStuInfo(student);
if (IsUpdate)
{
Page.RegisterStartupScript("check", "<script>alert('修改成功!');</script>");
//Response.Write("<script>alert('修改成功!');</script>");
}
else
{
Page.RegisterStartupScript("check", "<script>alert('操作失败!');</script>");
}
}
catch(FormatException ex)
{
Page.RegisterStartupScript("check", "<script>alert('请确认是否所有类型均输入正确!');</script>");
}
catch (Exception ex)
{
throw ex;
//Page.RegisterStartupScript("check", "<script>alert('数据库错误!');</script>");
}
求解!!!