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 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法