为什么它不去判断VU方法啊啊啊?~~~namespace 自作账号密码验证
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }        private void button1_Click(object sender, EventArgs e)
        {
            bool VU = true;
            string message = "";            if (VU)
            {
                if (comboBox1.Text == "管理员")
                {
                    Form2 form2 = new Form2();
                    form2.Show();
                    this.Visible = false;
                }            }
            
        }
        public bool VU(string loginId, string loginPwd, string loginType, ref string message)
        {
                        if (loginType == "管理员")
            {
                string sql = string.Format("SELECT COUNT (*) FROM Admin WHERE LoginId='{0}'AND LoginPwd='{1}'", loginId, loginPwd);
                try
                {
                    SqlCommand command = new SqlCommand(sql, DBHelper.connection);
                    DBHelper.connection.Open();
                    int count = (int)command.ExecuteScalar();
                    if (count < 1)
                    {
                        message = "!!!!!!!!";
                        return false;
                    }
                    else { return true; }
                }
                catch (Exception ex)
                {
                    message = "suju!!!";
                    Console.WriteLine(ex.Message);
                    return true;
                }
                finally { DBHelper.connection.Close(); }
            }
            message = "xuanze!";
            return false;
        }        private void Form1_Load(object sender, EventArgs e)
        {        }
    }
}

解决方案 »

  1.   

      if (VU)
      这个VU使用的是局部变量bool VU = true;  与方法VU()无关
      

  2.   

    你写的vu不是变量么,你要是要vu方法那就加上参数啊
      

  3.   

     if (VU)应该是if (VU(loginId, loginPwd, loginType, ref message))
    调用方法应该带括号。还应该有参数的
      

  4.   

    编译时类型选择变量而非函数如果要让编译器认为是函数 VU()那必须给定参数 VU(string loginId, string loginPwd, string loginType, ref string message)if(VU(p1, p2 ...)) {
     ...
    }
      

  5.   

    this.VU(,,,)//调用方法! 为什么?因为你的VU是局部变量,局部范围内它做主。
      

  6.   

    其实应该这样:
    bool VU= true;
    VU=VU();
    if(VU)
    {}public bool VU()
    {
    }如果VU()有参数就带参数
      

  7.   

    bool VU = true  注意啊 命名规范,最好不要出现局部变量跟方法名相同的  你那个if判断的是bool VU  不是方法
      

  8.   


    如果不影响你的结果的话,不知道的参数可用“”或者null代替
      

  9.   

    private void Judge()
    {
    bool flag=true;
    flag= VU();
    }
    public bool VU()
    {
    return true;//返回值
    }
    其实就是VU方法返回是true与false