| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 969 人关注过本帖
标题:[求助]ASP.NET 注册页面提交出现问题-->天使不哭转移
只看楼主 加入收藏
bavfhpdn66
Rank: 1
等 级:新手上路
威 望:1
帖 子:72
专家分:0
注 册:2007-4-11
收藏
 问题点数:0 回复次数:5 
[求助]ASP.NET 注册页面提交出现问题-->天使不哭转移

下面注册页面的代码:

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;
using System.Data.SqlClient;

public partial class login : System.Web.UI.Page
{
SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ccc"]);
Class2 sh = new Class2();
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
if (useryz(TextBox1.Text.ToString())) //验证用户是否已存在
{
return;
}
strcon.Close();
strcon.Open();
string cardtype;
string username = TextBox1.Text.ToString();
string truename = TextBox2.Text.ToString();
string password = TextBox3.Text.ToString();
string city = TextBox5.Text.ToString();
string address = TextBox6.Text.ToString();
string postcode = TextBox7.Text.ToString();
string cardno = TextBox8.Text.ToString();
//RBL1.Items[0].Selected = true;
if (RBL1.Items[0].Selected)
cardtype = "身份证";
else
if (RBL1.Items[1].Selected)
cardtype = "学生证";
else
cardtype = "其它";
string tel = TextBox9.Text.ToString();
string email = TextBox10.Text.ToString();
string sqlinsert = "insert into tb_member (username,truename,password,city,address,postcode,cardno,cardtype,tel,email) values('" + username + "','" + truename + "','" + password + "','" + city + "','" + address + "','" + postcode + "','" + cardno + "','" + cardtype + "','" + tel + "','" + email + "')";
SqlCommand comm = strcon.CreateCommand();
comm.CommandText = sqlinsert;
SqlTransaction myTransaction = strcon.BeginTransaction(); //开始一个事务
comm.Transaction = myTransaction;
try
{
comm.ExecuteNonQuery();
myTransaction.Commit(); //提交事务
ClearTextBox();
string mes = "恭喜 注册成功!";
Response.Write("<script>alert('" + mes + "');location='login.aspx'</script>");

}
catch
{
myTransaction.Rollback(); //回滚事务
}
finally
{
ClearTextBox();
strcon.Close();
}
}
protected Boolean useryz(string username) //验证用户是否已存在
{
strcon.Open();
SqlCommand comm = strcon.CreateCommand();
comm.CommandText = "select username from tb_member";
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
if (reader[0].ToString() == username)
{
Response.Write(sh.showmessage("该用户已存在!"));
strcon.Close();
return true ;
}
}
strcon.Close();
return false;
}
protected void RBL1_SelectedIndexChanged(object sender, EventArgs e)
{

}
protected void Button3_Click(object sender, EventArgs e)
{
ClearTextBox();
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("../Default.aspx");
}
protected void ClearTextBox()
{
TextBox1.Text = string.Empty;
TextBox2.Text = string.Empty;
TextBox3.Text = string.Empty;
TextBox4.Text = string.Empty;
TextBox5.Text = string.Empty;
TextBox6.Text = string.Empty;
TextBox7.Text = string.Empty;
TextBox8.Text = string.Empty;
TextBox9.Text = string.Empty;
TextBox10.Text = string.Empty;
}
}
当我填写好注册信息后提交时不成功!
后来我就单步运行
当执行到 try
{
comm.ExecuteNonQuery();时就跳到
catch
{
myTransaction.Rollback(); //回滚事务
}

结果数据都没写到数据库

想在此请教大家一下
错在哪里?
谢谢大家!

搜索更多相关主题的帖子: NET 天使 ASP 页面 
2007-04-20 15:52
xufengtang
Rank: 1
等 级:新手上路
威 望:1
帖 子:89
专家分:0
注 册:2006-5-7
收藏
得分:0 

会不会是strcon类写的有问题呢,观望着.....


2007-04-20 16:21
bavfhpdn66
Rank: 1
等 级:新手上路
威 望:1
帖 子:72
专家分:0
注 册:2007-4-11
收藏
得分:0 

呵呵
小弟下不为例!


奋起直追,犹未晚也!
2007-04-23 03:10
skyland84
Rank: 2
等 级:新手上路
威 望:4
帖 子:544
专家分:0
注 册:2006-10-9
收藏
得分:0 
SqlCommand comm = strcon.CreateCommand();
//comm.Connection=?;你还没有设置的连接是什么呢?我看了看你的代码 好像没有这个!这样应该在执行的时候会出现异常!提示没有连接到数据库!
comm.CommandText = sqlinsert;
SqlTransaction myTransaction = strcon.BeginTransaction(); //开始一个事务
comm.Transaction = myTransaction;
try
{
comm.ExecuteNonQuery();
myTransaction.Commit(); //提交事务
ClearTextBox();
string mes = "恭喜 注册成功!";
Response.Write("<script>alert('" + mes + "');location='login.aspx'</script>");

}
catch
{
myTransaction.Rollback(); //回滚事务
}
finally
{
ClearTextBox();
strcon.Close();
}

决定人生~
2007-04-23 11:23
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
在 catch 后面加个(Exception e)
再在下面输出相应的错误信息嘛.
Response.Write(e.ToString());这样不就知道是哪里的错了啊???

飘过~~
2007-04-23 12:32
bavfhpdn66
Rank: 1
等 级:新手上路
威 望:1
帖 子:72
专家分:0
注 册:2007-4-11
收藏
得分:0 
呵呵
谢谢大家
这个问题我已经PASS

奋起直追,犹未晚也!
2007-04-23 12:54
快速回复:[求助]ASP.NET 注册页面提交出现问题-->天使不哭转移
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021158 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved