本帖最后由 chenjinglong 于 2013-09-20 18:36:47 编辑

解决方案 »

  1.   

    用户名是否为空判断
     private bool checkEmpty()
            {
                bool result = true;  //定义默认返回结果为true            if (txtUserName.Text.Trim() == string.Empty)
                {
                    lblUserEmpty.Visible = true;
                    result = false;
                }
                else
                {
                    lblUserEmpty.Visible = false;            }            if (txtPassWord.Text == string.Empty)
                {
                    lblPassEmpty.Visible = true;
                    result = false;
                }
                else
                {
                    lblPassEmpty.Visible = false;
                }
                return result;
            }
      

  2.   

    注册代码实现:
           private bool checkEmpty()
            {
                bool result = true;
                if (txtUserName.Text.Trim() == string.Empty)
                {
                    lblUserError.Visible = true;
                    result = false;
                }
                else
                {
                    lblUserError.Visible = false;
                }
                if (txtPassWord.Text == string.Empty)
                {
                    lblPassError.Visible = true;
                    result = false;
                }
                else
                {
                    lblPassError.Visible = false;
                }
                if (txtCPass.Text == string.Empty)
                {
                    lblCoformError.Visible = true;
                    result = false;
                }
                else if (txtPassWord.Text != txtCPass.Text)
                {
                    lblPassError.Visible = false;
                    lblCoformError.Visible = false;
                    MessageBox.Show("密码不匹配请重新输入,请重新输入");
                    txtPassWord.Clear();
                    txtCPass.Clear();
                    result = false;
                }            return result;
            }        private void btnRegist_Click(object sender, EventArgs e)
            {
               // SqlCommand ins = null;
                bool isEmpty = checkEmpty();
                if (isEmpty == true)
                {
                    try
                    {
                        DBHelper.connect.Open();
                        string sql = string.Format(@"insert into [FamilyUser] values('{0}','{1}')", txtUserName.Text.Trim(), txtPassWord.Text);
                        SqlCommand ins = new SqlCommand(sql, DBHelper.connect);
                        int count = ins.ExecuteNonQuery();
                        if (count == 1)
                        {                        MessageBox.Show("你已经成功注册");
                            this.Close();                    }
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show("注册失败 原因如下" + ex.Message);
                    }
                    finally
                    {
                        
                        DBHelper.connect.Close();
                    }
                }
      

  3.   

    代码分享?你不如把完整的项目上传到download.csdn.net中,然后把链接贴出来。