注册提示成功,可是数据库里就没有注册的内容
注册页面)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;
public partial class Reg : WebPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOK_Click(object sender, EventArgs e)
{
if (this.Session["VNum"] + "" != this.txtVNum.Text)
{
this.SendMessage("验证码不正确");
}
else if (this.txtIDCard.Text.Substring(6, 8) != DateTime.Parse(this.txtBirthday.Text).ToString("yyyyMMdd"))
{
this.SendMessage("身份证日期和填写的出生日期不符合");
}
else
{
StudentMgr mgr = new StudentMgr();
Student student = new Student();
student.StudentID = CMMgr.GetNextIDValue("StudentID").ToString();
student.StudentName = this.txtStudentName.Text;
student.Sex = this.lstSex.SelectedValue;
// student.Address = this.txtAddress.Text;
student.Birthday = DateTime.Parse(this.txtBirthday.Text);
//student.Code = this.txtCode.Text;
student.EMail = this.txtEMail.Text;
student.IDCard = this.txtIDCard.Text;
//student.Mobile = this.txtMobile.Text;
//student.SchoolAge = this.txtSchoolAge.Text;
//student.Speciality = this.txtSpeciality.Text;
// student.Tel = this.txtTel.Text;
if (this.txtPassword1.Text != "")
{
student.Password = this.txtPassword1.Text;
}
if (this.FilePath.HasFile)
{
if (System.IO.Path.GetExtension(this.FilePath.FileName).ToLower() == ".jpg")
{
string strFileName = this.GetRand(10000000, 99999999).ToString() + System.IO.Path.GetExtension(this.FilePath.FileName);
this.FilePath.SaveAs(Server.MapPath("UpdateFile/") + strFileName);
student.FilePath = strFileName;
}
else
{
this.SendMessage("上传照片必须为jpg类型,您上传的照片为" + System.IO.Path.GetExtension(this.FilePath.FileName).ToLower() + "类型");
return;
}
}
mgr.UpdateStudent(student, 1);
this.SendMessage("注册成功,您的考号为" + student.StudentID);
this.ClearTextData(this);
}
}
}
做的StudentMgr
public class StudentMgr--------------------编程问答-------------------- try
{
private string Picture;
public StudentMgr()
{
}
public string picture
{
set
{
this.Picture = value;
}
get
{
return this.Picture;
}
}
public void getstudent(string StudentID)//获得准考证照片
{
CMMgr cmg = new CMMgr();
string sql1 = "select * from Student where StudentID = " + StudentID;
DataRow dr1 = cmg.GetDataRow(sql1);
if (dr1 != null)
{
this.Picture = CMMgr.ValidateDataRow_S(dr1, "FilePath");
}
}
#region 函数UpdateStudent | 更新人员信息
/// <summary>
/// 更新一个人员信息
/// </summary>
/// <param name="student">人员类</param>
/// <param name="IsNew">是否为新增1为新增,0为否</param>
/// <returns>更新成功返回true 否则返回false</returns>
public bool UpdateStudent(Student student,int IsNew)
{
bool ReturnValue = false;
CMMgr cmmgr = new CMMgr("Pro_EditStudent");
cmmgr.CommandType = CommandType.StoredProcedure;
cmmgr.SetParameter("@StudentID", student.StudentID, SqlDbType.NVarChar);
cmmgr.SetParameter("@Password", student.Password, SqlDbType.NVarChar);
cmmgr.SetParameter("@StudentName", student.StudentName, SqlDbType.NVarChar);
cmmgr.SetParameter("@IDCard", student.IDCard, SqlDbType.NVarChar);
cmmgr.SetParameter("@Birthday", student.Birthday, SqlDbType.DateTime);
cmmgr.SetParameter("@Sex", student.Sex, SqlDbType.NVarChar);
cmmgr.SetParameter("@EMail", student.EMail, SqlDbType.NVarChar);
cmmgr.SetParameter("@FilePath", student.FilePath, SqlDbType.NVarChar);
cmmgr.SetParameter("@EditType", IsNew, SqlDbType.Int);
try
{
cmmgr.ExecuteNonQuery();
ReturnValue = true;
}
catch (SqlException err)
{
ErrLog.WriteErrLog("人员更新错误发生在StudentMgr.UpdateStudent()中:" + err.Message);
}
catch (Exception err)
{
ErrLog.WriteErrLog("人员更新错误发生在StudentMgr.UpdateStudent()中:" + err.Message);
}
finally
{
cmmgr.Close();
}
return ReturnValue;
}
{
int temp= cmmgr.ExecuteNonQuery();
ReturnValue = temp>0;
} --------------------编程问答--------------------
写法也有问题,UpdateStudent方法明显有返回值,你不判断是否为true,直接在后面输出信息,是不对的。
--------------------编程问答-------------------- 太多代码了 --------------------编程问答-------------------- bool result=mgr.UpdateStudent(student, 1);
try{
bool flag = mgr.UpdateStudent(student, 1);
if(flag)
{
this.SendMessage("注册成功,您的考号为" + student.StudentID);
this.ClearTextData(this);
}
}
catch(Exception ex){
// 看看这里有什么异常,很可能是你传递的参数为空,或者类型不对所导致
}
if(bool)
{}
else
{} --------------------编程问答-------------------- 方法有问题啊,没有对数据库造成影响
看存储过程有木有问题 --------------------编程问答-------------------- 你要看 mgr.UpdateStudent(student, 1);这句执行成功没有。 --------------------编程问答-------------------- mgr.UpdateStudent(student, 1);
this.SendMessage("注册成功,您的考号为" + student.StudentID);
this.ClearTextData(this);
mgr.UpdateStudent(student, 1);这个方法里处理掉了错误,页面不会报错。
所以不管什么情况都会执行到这行this.SendMessage("注册成功,您的考号为" + student.StudentID);
解决办法:判断mgr.UpdateStudent(student, 1);的返回值,为true才执行this.SendMessage("注册成功,您的考号为" + student.StudentID);
补充:.NET技术 , ASP.NET