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

下面是注册页面后台代码:
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 UserControls_Register : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOK_Click(object sender, EventArgs e)
{
this.MultiView1.ActiveViewIndex = 1;
}

protected void btnOK1_Click(object sender, EventArgs e)
{
SqlData da = new SqlData();
SqlDataReader read = da.ExceRead("select * from tb_UserLW where Uid='" + this.txtUid.Text + "'");
read.Read();
if (read.HasRows)
{
if (this.txtUid.Text == read["Uid"].ToString())
{
Response.Write("<script language=javascript>alert('对不起,该用户已经注册!');location='Register.aspx'</script>");
return;
}
}
read.Close();
string cmdtxt = "INSERT INTO tb_UserLW(Uid,Pwd,Sex,WebSite,Email,QQ,IP)";
cmdtxt += " VALUES('" + this.txtUid.Text + "','" + this.txtPwd.Text + "','" + this.radSex.SelectedValue+ "'";
cmdtxt += ",'" + this.txtWebSite.Text + "','" + this.txtEmail.Text + "','" + this.txtQQ.Text + "'";
cmdtxt += ",'" + Request.UserHostAddress + "')";
bool add = da.ExceSQL(cmdtxt);
if (add == true)
{
Response.Write("<script language=javascript>alert('注册成功!');location='Register.aspx'</script>");
}
else
{
Response.Write("<script language=javascript>alert('注册失败!');location='javascript:history.go(-1)'</script>");
}
}

protected void btnNoOK_Click(object sender, EventArgs e)
{
Response.Redirect("Index.aspx");
}
}

下面是公共类的代码:
using System;
using System.Data;
using System.Configuration;
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;

/// <summary>
/// SqlData 的摘要说明
/// </summary>
public class SqlData
{
private SqlConnection sqlcon;
private SqlCommand sqlcom;
private SqlDataAdapter sqldata;
public SqlData()
{
sqlcon = new SqlConnection(ConfigurationManager.AppSettings["strcon"]);
sqlcon.Open();
}
public bool ExceSQL(string SqlCom)
{
sqlcom = new SqlCommand(SqlCom, sqlcon);
try
{
sqlcom.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
finally
{
sqlcon.Close();
}
}
public DataSet ExceDS(string SqlCom)
{
try
{
sqlcom = new SqlCommand(SqlCom, sqlcon);
sqldata = new SqlDataAdapter();
sqldata.SelectCommand = sqlcom;
DataSet ds = new DataSet();
sqldata.Fill(ds);
return ds;

}
finally
{
sqlcon.Close();
}
}
public SqlDataReader ExceRead(string SqlCom)
{
sqlcom = new SqlCommand(SqlCom, sqlcon);
SqlDataReader read = sqlcom.ExecuteReader();
return read;
}
}


当我填好注册信息后提交 并单步运行时出现异常!
运行到“红色”那一行后马上运行到 catch
{
return false;
}
最后提示“注册失败”对话框

搜索更多相关主题的帖子: 注册 页面 天使 
2007-05-01 13:19
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
哪一行是红色的??

飘过~~
2007-05-01 15:49
bavfhpdn66
Rank: 1
等 级:新手上路
威 望:1
帖 子:72
专家分:0
注 册:2007-4-11
收藏
得分:0 
try
{
sqlcom.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
finally
{
sqlcon.Close();
}
}
public DataSet ExceDS(string SqlCom)
{

奋起直追,犹未晚也!
2007-05-01 19:09
快速回复:[求助]“注册页面”提交出现异常(急)!-->天使不哭转移
数据加载中...
 
   



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

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