兄弟,这里出错了:       if (table.Rows.Count > 0)
                    {
                        //MessageBox.Show("登录成功!");
                        Form f3 = new Form3();
                        f3.Show();
                        //this.Hide();
                    }
是这样的: From3 f3=new Form3();
                  f3.Show();
你再试试

解决方案 »

  1.   

    第一感觉是f3应该设置成 成员变量,而不是局部变量,以防止被GC回收。但是试了一下好像没有问题, 下面的代码在我这里没有问题:      private void button1_Click_1(object sender, EventArgs e)
            {
                if (button1.Text != "")
                {
                    Form form2 = new Form2();
                    form2.Show();                    this.Hide();
                }        }你可以改成成员变量试一试。
      

  2.   

    另外跟踪下show form的代码走到了没有。
      

  3.   

    http://blog.csdn.net/wuyazhe/article/details/5642431
      

  4.   

    完成登录系统功能,输出相应设置页面示例
    //加载记录用户名状态
     protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null && Session["UserPwd"] != null)
            {
              
                Session["UserName"] = null;
                Session["UserPwd"] = null;
            }
        }
    //从新跳转到注册页面
     protected void ImgBtnzhuce_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("zhuce.aspx"); //跳转到注册页面中
        }
    //登录事件如果成功跳转到相应页面
     protected void ImgBtnLogin_Click(object sender, ImageClickEventArgs e)
        {
            int i = this.checkLogin(this.TxtName.Text, this.TxtPwd.Text);
            
            if (i > 0)
            {
              Session["UserName"] =this.TxtName.Text;
              Session["UserPwd"] = this.TxtPwd.Text;
              Response.Redirect("Default.aspx");//登录成功后跳转到Default.aspx页面中
              
            }
            else//调用方法调用失败,弹出提示对话框
            {
                Response.Write("<script language=javascript>alert('很遗憾,用户名称或密码错误!');location='javascript:history.go(-1)'</script>");
            }
        }
    //检测数据库用户名密码填写是否正确checkLogin事件
    public int checkLogin(string loginName, string loginPwd)
        {
            SqlConnection con = new SqlConnection(Memobwl.GetConStr());
            SqlCommand myCommand = new SqlCommand("select count(*) from tb_Login where name=@loginName and Pwd=@loginPwd ", con);
            myCommand.Parameters.Add(new SqlParameter("@loginName", SqlDbType.VarChar, 50));
            myCommand.Parameters["@loginName"].Value = loginName;
            myCommand.Parameters.Add(new SqlParameter("@loginPwd", SqlDbType.VarChar, 50));
            myCommand.Parameters["@loginPwd"].Value = loginPwd;
            myCommand.Connection.Open();//打开数据库连接
            int i = (int)myCommand.ExecuteScalar();//执行SQL语句
            myCommand.Connection.Close();//关闭数据库连接
            return i;
        }
      

  5.   

    按照你说的改了 ,如果messagebox没被注释,也弹不出来,我在想是不是select语句写错了,但是看看也没错啊,data source是用windows身份验证的,有问题吗?
      

  6.   

    断点跟啊,看查询出来到底有没有数据
    而且select语句这样写,如果登陆不成功,很难判断到底为什么不成功
    你应该这样写:select * from 表 where 用户名=''
    判断行数大于0之后,再验证密码是否相同
    这样才好区分是用户名不存在,还是密码错误.
    不要把用户名和密码一起用来查询
      

  7.   

     if (table.Rows.Count > 0)
                        {
                            //MessageBox.Show("登录成功!");
                            Form f3 = new Form3();
                            f3.Show();
                            //this.Hide();
                        }
    这里要加else啊,提示到底怎么了
    不要行数为0,点了就没反应了啊
      

  8.   

    会不会是我的数据库文件有问题啊?设置个断点, debug跟踪一下就知道了。
      

  9.   

    会不会是我的数据库文件有问题啊?设置个断点, debug跟踪一下就知道了。额 我看了一下 table.rows.count=0 这是怎么回事?
      

  10.   


    用户名或密码错误!可以debug的时候,把sql的值拿出来执行,看看有没有结果。
      

  11.   

      adapter.InsertCommand = builder.GetInsertCommand();
                        table.Clear();//这里不是Clear了???
                        adapter.Fill(table);
      

  12.   

    好好看我在7楼说的,把select语句分开,不要把用户名和密码一起提交
    这样你才能看出到底是用户名错误,还是密码错误
    然后再对比数据库里的字段,看到底哪里没有匹配上
      

  13.   

    调试时,把sql的内容取出来,在数据库中执行以下就知道哪里错了。
      

  14.   

    string gonghao = comboBox1.Text;
                string mima = textBox1.Text;
                DataClasses1DataContext linq = new DataClasses1DataContext("Data Source=" + IP + ";Initial Catalog=XIAOBIAODI;Persist Security Info=True;User ID=dyp;Password=5219930407");
                var result = from v in linq.xinxi
                             where v.GONGHAO == gonghao && v.MIMA == mima
                             select v;
                if (result.Count() > 0)
                {                Form1 fm1 = new Form1();
                    fm1.comboBox1.Items.Add(gonghao);
                    fm1.comboBox1.Items.Add(mima);
                    var result1 = from bian in linq.xinxi
                                  where bian.GONGHAO == gonghao
                                  select bian;
                    foreach (xinxi li in result)
                    {
                        fm1.comboBox1.Items.Add(li.QUANXIAN1);
                        fm1.comboBox1.Items.Add(li.QUANXIAN2);
                    }
                    fm1.label1.Text = "1";                //ID = gonghao;                //    if (!File.Exists("C:\\Program Files\\Q test\\ID.txt"))
                    //    {
                    //        FileStream fs = new FileStream("C:\\Program Files\\Q test\\ID.txt", FileMode.Create, FileAccess.Write);
                    //        StreamWriter sw = new StreamWriter(fs);
                    //        sw.WriteLine(ID);
                    //        sw.Close();
                    //        fs.Close();
                    //    }
                    //    else
                    //    {
                    //        string aa = File.ReadAllText("C:\\Program Files\\Q test\\ID.txt");
                    //        FileStream fs = new FileStream("C:\\Program Files\\Q test\\ID.txt", FileMode.Open, FileAccess.Write);
                    //        StreamWriter sr = new StreamWriter(fs);
                    //        sr.WriteLine(ID + "\r\n" + aa);
                    //        sr.Close();
                    //        fs.Close();
                    //    }
                        Program.context.MainForm = fm1;
                        fm1.Show();
                        this.Close();
      

  15.   

    这样写,试试,我用的是MySQL数据库,需要改一下,sql语句也需要改一下
    string connString = "Database=db_mrcy;Data Source=localhost;User Id=root;Password=111;pooling=false;CharSet=utf8;port=3306";
                    string sql = "select * from tb_user where UserName='" + textBox1.Text + "' and UserPwd ='" + textBox2.Text + "'";
                    using (MySqlConnection conn1 = new MySqlConnection(connString))
                    {
                        conn1.Open();
                        using (MySqlDataAdapter sda = new MySqlDataAdapter(sql, conn1))
                        {
                            // DataSet ds = new DataSet();
                            DataTable dt = new DataTable();
                            sda.Fill(dt);
                            if (dt.Rows.Count > 0)
                            {
                                MessageBox.Show("登录成功");
                            }
                            else
                            {
                                MessageBox.Show("登录失败");
                            }
                        }
                    }