zzccxx5 2017-06-26 03:29 采纳率: 80%
浏览 779
已采纳

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

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 2017-06-26 06:08
    关注

    cmd3 .ExecuteNonQuery();

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 电脑开机过商标后就直接这样,求解各位
  • ¥15 mysql , 用自己创建的本地主机和用户名 登录不上
  • ¥15 关于#web项目#的问题,请各位专家解答!
  • ¥15 vmtools环境不正常
  • ¥15 请问如何在Ubuntu系统中安装使用microsoft R open?
  • ¥15 jupyter notebook
  • ¥30 informer时间序列预测
  • ¥20 SSR引物多态性分析
  • ¥15 大漠插件在Win11易语言注册调用和免注册灵异事件,VS上注册调用完全没问题
  • ¥15 Addressable缓存机制做热更新的问题