c# asp.net 编写注册按钮的问题

来源:百度知道 编辑:UC知道 时间:2024/05/13 02:14:46
private void Button1_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
//用Connection对象连接数据库
string connStr=
System.Configuration.ConfigurationSettings.AppSettings
["connString"];
SqlConnection myConnection=new SqlConnection(connStr);

//检测用户名(username)是否已经存在
string checkStr="select count(*) from bbs_register where username='"+username.Text+"'";
SqlCommand myCommand1=new SqlCommand(checkStr,myConnection);

myConnection.Open();
int flag=(int)myCommand1.ExecuteScalar();
myConnection.Close();
string Message;
//用户名没有被占用
if(flag==0)
{
//插入一条新记录
string gender=null;
if(male.Checked) gender="男";
if(female.Checked) gender="女";

string inserStr="INSERT INTO bbs_register VALUES ('"+username.Text+&qu

catch (Exception ex)
{
Message=ex.Message;
}

看下是什么异常就知道了

问题补充:说得详细点好吗? 不好意思 我没看明白
把你的异常捕捉代码,改成上面的样子,看看是什么异常

string inserStr="INSERT INTO bbs_register VALUES ('"+username.Text+"','"+pwd.Text+"','"+confirmpwd.Text+"')";
是不是字符串换行的问题???