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 filenotfounderror:文件是存在的,权限也给了,但还一直报错
  • ¥15 关于远程桌面的鼠标位置转换
  • ¥15 MATLAB和mosek的求解问题
  • ¥20 修改中兴光猫sn的时候提示失败
  • ¥15 java大作业爬取网页
  • ¥15 怎么获取欧易的btc永续合约和交割合约的5m级的历史数据用来回测套利策略?
  • ¥15 有没有办法利用libusb读取usb设备数据
  • ¥15 为什么openeluer里面按不了python3呢?
  • ¥15 关于#matlab#的问题:训练序列与输入层维度不一样
  • ¥15 关于Ubuntu20.04.3LTS遇到的问题:在安装完CUDA驱动后,电脑会进入卡死的情况,但可以通过键盘按键进入安全重启,但重启完又会进入该情况!