首页 新闻 会员 周边 捐助

谁看下什么问题,找了半天找不到

0
悬赏园豆:5 [待解决问题]

protected void Button1_Click(object sender, EventArgs e)
{

    string text1 = TextBox3.Text;//用户名
    string text2 = TextBox4.Text;//密码
    string text3 = TextBox1.Text;//email
    string text4 = TextBox2.Text;//telphone
    SqlConnection myconn = new SqlConnection();
    string cmdtext = "insert into register values(" + "'" + text1 + "'" + "," + "'" + text2 + "'" + "," + "'" + text3 + "'"+ "," + "'" + text4 + "'"+")";
  //  string cmdtext = "select * from login where username =" + "'" + text1 + "'";
    string cmdtext0 = "select * from register where username =" + "'" + text1 + "'";

    SqlCommand mycommand = new SqlCommand(cmdtext0, myconn);
    myconn.ConnectionString = myconn_str;

    int index=0;
    // string output = "<table border=1>";
    myconn.Open();

    index = mycommand.ExecuteNonQuery();  //  ------------------>index = -1

 //   MessageBox.Show("index =" + index.ToString());

    if (index == 0) //名字没有被注册
    {
        mycommand.CommandText = cmdtext;

        index = mycommand.ExecuteNonQuery();

        if (index == 1)
        {
            MessageBox.Show("Register successfully");

        }

    }
    else if(index == 1)
    {
        MessageBox.Show("Your name is already existed!");
        empty();
    }
    else
    {
        MessageBox.Show("system exception");
    }
    myconn.Close();
 
}
gzjiuying的主页 gzjiuying | 菜鸟二级 | 园豆:205
提问于:2025-07-01 07:32
< >
分享
所有回答(2)
0

你想问什么问题

慧☆星 | 园豆:5809 (大侠五级) | 2025-07-01 09:38
0

index = mycommand.ExecuteNonQuery(); // ------------------>index = -1这里写得不对,
SQL语句 查询 不是ExecuteNonQuery ,你应该把结果存在DataSet,DataTable中。然后查询DataTable中有没有数据,来判断 这个人有没有已经注册

需要格局 | 园豆:2147 (老鸟四级) | 2025-07-01 18:52

如果用 插入语句index = 1 怎么解释

支持(0) 反对(0) gzjiuying | 园豆:205 (菜鸟二级) | 2025-07-02 15:00

mycommand.ExecuteNonQuery(); 是返回一个整型数据

支持(0) 反对(0) gzjiuying | 园豆:205 (菜鸟二级) | 2025-07-02 15:06

@gzjiuying:
string cmdtext0 = "select * from register where username =" + "'" + text1 + "'";

SqlCommand mycommand = new SqlCommand(cmdtext0, myconn);

你没发现么?这里你使用的是查询语句 ,不是插入语句。
你查询的话 ,就不要用ExecuteNonQuery,ExecuteNonQuery 返回值是 "受影响的行数"。

支持(1) 反对(0) 需要格局 | 园豆:2147 (老鸟四级) | 2025-07-03 10:50

@gzjiuying: 我的5个园豆呢?怎么不给我

支持(0) 反对(0) 需要格局 | 园豆:2147 (老鸟四级) | 2025-07-09 09:06

@需要格局: 好,给你!

支持(0) 反对(0) gzjiuying | 园豆:205 (菜鸟二级) | 2025-07-12 09:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册