weixin_38596791 2017-05-19 08:14 采纳率: 75%
浏览 1055
已采纳

VS中关于注册功能的实现有点小问题

求问各位,看看我的注册代码哪里出问题了,用户名和密码都可以判断成功,就是写不进数据库里,要怎么修改 protected void btnRegister_Click(object sender, EventArgs e)
{
//判断是否已存在用户
string strUser = tbusername.Text.Trim();
string strPsw = tbpsw.Text.Trim();
string strSql = string.Format("select * from tbUser where name='{0}'", strUser);

        string connStr = ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString;
        SqlConnection sqlConn = new SqlConnection();
        sqlConn.ConnectionString = connStr;
        sqlConn.Open();
        SqlCommand cmd = new SqlCommand(strSql, sqlConn);
        cmd.CommandType = CommandType.Text;
        SqlDataReader sdr =cmd .ExecuteReader();
        sdr.Read ();

        DataTable dtUser = new DataTable();//执行SQL语句,并返回执行结果,转载到DataTable中   
        if (sdr.HasRows)
             {
                 Response.Write(@"<script>alert('用户已存在,请重新输入');</script>");
             }     
        else  
           {
               //判断用户两次输入的密码是否一致            
                 if (this.tbpsw.Text == this.tbpsw1.Text && this.tbpsw.Text != null)
              {
               sdr.Close();
               string sql = string.Format("insert into tbUser(name,password)values ('" + tbusername.Text + "','" + tbpsw.Text + "')");
               SqlCommand mycom  = new SqlCommand(strSql, sqlConn);
               mycom .ExecuteNonQuery();
               sqlConn.Close();
               sqlConn.Dispose();
               Session["user"] = strUser; 
               Response .Write(@"<script>alert('注册成功!');</script>");
               Response.Redirect("~/loading.aspx");
              }
                 else
              {
               Response.Write(@"<script>alert('请确认两次输入密码一致!');</script>");
               tbusername.Text = tbpsw.Text = string.Empty; 
               }
            }




    }
  • 写回答

1条回答 默认 最新

  • 战在春秋 2017-05-19 10:06
    关注
     string sql = string.Format("insert into tbUser(name,password)values ('" + tbusername.Text + "','" + tbpsw.Text + "')");
    

    这行代码中包含 name,password 的括号不是英文状态的括号,是全角字符。
    注意

     ( 和 (
    

    的区别

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用