问题:如题;
目的:设计一用户注册页面,在代码内实现查询比较,避免重复注册

解决方案 »

  1.   

    select count(*) from t_user where t_user.name='name'
      

  2.   

    页面TextBox2
    数据库User表Name项
    代码if(***){    }
    问题就在于***如何操作select 出来后,返回的是什么呢?
      

  3.   

    string strConn = "";//连接你自己写吧
    string strSQL = "Select COUNT(*) From User Where Name = '" + TextBox2.Text + "'";
    System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(strConn);
    conn.Open();
    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(strSQL);
    int count = Convert.ToInt32(cmd.ExecuteScalar());
    if (count > 0)
    {
    //已经存在该用户
    }
    conn.Close();
      

  4.   

    sqlConnection1.Open();
    string sqlStr="SELECT * FROM XX"; 
    SqlCommand cmd=new SqlCommand(sqlStr,sqlConnection1);
    SqlDataReader dataReader= cmd.ExecuteReader();
    while(dataReader.Read())
    {
    string RegID=dataReader["ID"].ToString().Replace(" ","");
    ifRegBox.Text.ToString().Replace(" ","")==RegID)
    {
    MessageBox.show("小样,请别重复注册");
    }}
      

  5.   

    ```漏了个括号```
    sqlConnection1.Open();
    string sqlStr="SELECT * FROM XX"; 
    SqlCommand cmd=new SqlCommand(sqlStr,sqlConnection1);
    SqlDataReader dataReader= cmd.ExecuteReader();
    while(dataReader.Read())
    {
    string RegID=dataReader["ID"].ToString().Replace(" ","");
    if(RegBox.Text.ToString().Replace(" ","")==RegID)
    {
    MessageBox.show("小样,请别重复注册");
    }
      

  6.   

    Snowdust(雪尘) 你怎么老和我抢分
      

  7.   

    SqlConnection con = new SqlConnection();
            con.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["DSN"];
            con.Open();        string strSql = "select * from GustReg.UserName = '" + tbUserName.Text + "'";
            SqlCommand com = new SqlCommand(strSql, con);
            SqlDataReader dr = com.ExecuteReader();
            bool bExist = false;
            while (dr.Read())
            {
                bExist = true;
                Session["AdmName"] = dr.GetString(0);
            }
            if (bExist)
            {
                Response.Write("<script language='javascript'>alert('用户名已存在,请更换用户名注册')</script>");
            }