zzccxx5
zzccxx5
采纳率80%
2017-06-26 03:29 阅读 771

注册信息填入过后无法成功找到已填入信息,也就是说插入表失败

5

string strSQL = "insert into user values ";
strCon += "('" + this.username_txt.Text + "','" + this.password_txt.Text + "','" + this.email_txt.Text + "','" + this.address_txt.Text + "',";
strSQL += "' " + this.familyname_txt.Text + "','" + this.givenname_txt.Text + "','" + this.idcard_txt.Text + "')";
请问这个插入语言有问题吗?注册过后找不到注册的信息,也就是说没能成功插入到user表中。
整个代码如下:
string strCon = WebConfigurationManager.ConnectionStrings["RAINBOWConnectionString"].ConnectionString;
SqlConnection sql = new SqlConnection();
sql.ConnectionString = strCon;
sql.Open();
SqlCommand cmd = new SqlCommand("select * from [user] where username='" + this.username_txt.Text + "'", sql);
SqlCommand cmd2 = new SqlCommand("select * from [user] where email='" + this.email_txt.Text + "'", sql);
string strSQL = "insert into user values ";
strCon += "('" + this.username_txt.Text + "','" + this.password_txt.Text + "','" + this.email_txt.Text + "','" + this.address_txt.Text + "',";
strSQL += "' " + this.familyname_txt.Text + "','" + this.givenname_txt.Text + "','" + this.idcard_txt.Text + "')";

    SqlCommand cmd3 = new SqlCommand(strSQL, sql);


    SqlDataReader dr = cmd.ExecuteReader();
    if (dr.Read())
    {
        this.Label1.Visible = true;
        dr = cmd2.ExecuteReader();
        if (dr.Read())
        {
            this.Label2.Visible = true;
            sql.Close();
        }
    }
    else
    {
        this.Label1.Visible = false;
        this.Label2.Visible = false;

        Server.Transfer("~/前台/Login.aspx");
    }
    sql.Close();
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • 已采纳
    liyunhusoso liyunhusoso 2017-06-26 06:08

    cmd3 .ExecuteNonQuery();

    点赞 评论 复制链接分享
  • sun1021873926 夕阳雨晴 2017-06-26 03:33

    插入表失败 ,有没有抛出什么异常呀?

    点赞 评论 复制链接分享
  • strutce 丵鹰 2017-06-26 03:41

    string strSQL = "insert into user values ";
    strCon += "('" + this.username_txt.Text + "','" + this.password_txt.Text + "','" + this.email_txt.Text + "','" + this.address_txt.Text + "',";
    strSQL += "' " + this.familyname_txt.Text + "','" + this.givenname_txt.Text + "','" + this.idcard_txt.Text + "')";

    第二句的strCon与strSQL不一样拼接不了成完整的sql字符串

    点赞 评论 复制链接分享
  • liyunhusoso liyunhusoso 2017-06-26 06:06

    cmd3 提交运行了吗?你只是给他赋值sql语句了 没有执行!!!!cmd3执行方法呢??????

    点赞 评论 复制链接分享

相关推荐