为什么注册新用户时信息注册不到数据库
using System;using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Drawing;
using System.IO;
using System.Data;
using System.Data.SqlClient;
public partial class CN_UserRegistration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BtnRegister.Enabled = true;
}
}
protected void BtnRegister_Click(object sender, EventArgs e)
{
if (LblExist.Text == "该用户已注册,请您更换其他用户名")
{
//Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Check", "alert('用户名重复,请重新输入用户名');", true);
}
else
{
//BtnRegister.Enabled = false;
string txtCheckCode = TxtCheckCode.Text;
UserInfo claUserInfo = new UserInfo();
Registration claReg = new Registration();
//进行对象赋值
claUserInfo.UserName = TxtUserName.Text.Trim();
claUserInfo.PassWord = TxtPassWord.Text.Trim();
claUserInfo.Email = TxtEmail.Text.Trim();
claUserInfo.Tel = TxtTel.Text.Trim();
claUserInfo.Role = "Tourist";
SqlConnection Conn = new SqlConnection(SQLHelper.strConnectionString);
Conn.Open();
SqlTransaction Trans = Conn.BeginTransaction();
SqlCommand Cmd = new SqlCommand();
Cmd.Connection = Conn;
Cmd.Transaction = Trans;
//暂时用来记录头像的编号
int ImgID = 0;
try
{
if (ImgFileUpLoad.HasFile)
{
ImgID = new UpLoad().ImgUpload(ImgFileUpLoad);
claUserInfo.ImageID = ImgID;
}
if (txtCheckCode == Session["checkcode"].ToString().ToLower())
{
int intReturn = claReg.Register(claUserInfo);
if (intReturn > 0)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Register", "alert('注册成功!');", true);
}
}
}
catch
{
Trans.Rollback();
}
finally
{
Conn.Close();
}
}
}
protected void TxtUserName_TextChanged(object sender, EventArgs e)
{
DataOperation Dop = new DataOperation();
StringBuilder claStrBud = new StringBuilder();
claStrBud.Append("SELECT [ID],[UserName],[PassWord],[Email],[Tel] FROM [dbo].[UserInfo] Where [UserName]='" + TxtUserName.Text.Trim() + "'");
if (Dop.IsDataFind(claStrBud.ToString()))
{
LblExist.Text = "该用户已注册,请您更换其他用户名";
LblExist.ForeColor = Color.Red;
LblExist.Visible = true;
}
else
{
LblExist.Text = "您可以使用该用户名";
LblExist.ForeColor = Color.Red;
LblExist.Visible = true;
}
}
}
--------------------编程问答-------------------- 没见你提交啊!try里面应该有个trans.commit()什么来的吧。 --------------------编程问答-------------------- f11单步,是否执行 --------------------编程问答--------------------
+1 像这种情况自己调试是最好找出错误的
--------------------编程问答--------------------
事务必须提交才能添加上信息的 --------------------编程问答-------------------- 我的天,SQL语句都写一起了!! --------------------编程问答-------------------- 现在注册数据库完全没有问题,可是上传图片无法上传ImgID,问题如下:
在Catch处出现“未能找到文件“C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\示例图片_01.jpg”。”
不知是什么原因图片一直在运行页面出现不了。 --------------------编程问答-------------------- --------------------编程问答-------------------- C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\示例图片_01.jpg”。”
你这个路径下有图片么?
你注册的时候是要图片路径存入数据库啊。 --------------------编程问答-------------------- 日,没有提交,靠,事物是要提交的... --------------------编程问答-------------------- 像这种情况 单步调试往下跟踪!! 最快最有笑的办法 !! --------------------编程问答-------------------- 事务要注意提交。
补充:.NET技术 , ASP.NET