我正在做一个工程的登陆界面,可是当我输入用户名、密码之后怎么又弹出来登陆的对话框呢?代码如下
private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtUsername.Text.Trim() == "")
            {
                MessageBox.Show("请输入用户名");
                txtUsername.Focus();
                return;
            }
            if (txtPsw.Text.Trim() == "")
            {
                MessageBox.Show("请输入密码");
                txtPsw.Focus();
                return;
            }
            // 获取用户信息
            else
            {
                string strSql = "select * from Users where UserName='" + txtUsername.Text + "' and UserPwd='" + txtPsw.Text + "'";
                DataSet ds = dataoperate.getDs(strSql, "Users");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    this.Hide();
                    MainForm mainform = new MainForm();
                    mainform.Show();
                  
                }
                else
                {
                    MessageBox.Show("用户名或密码错误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                
            }
        }
其中dataOperate类代码为    class DataOperate
    {
        DataConn datacon = new DataConn();
        OracleConnection oledbcon;
        OracleDataAdapter oledbda;
        DataSet ds;        public DataSet getDs(string strCon, string tbname)
        {
            oledbcon = datacon.conn;
            oledbda = new OracleDataAdapter(strCon, oledbcon);
            ds = new DataSet();
            oledbda.Fill(ds, tbname);
            return ds;
        }
    }

解决方案 »

  1.   

     public DataSet getDs(string strCon, string tbname)  
    改为 public DataSet getDs(string strCon)  oledbda.Fill(ds, tbname)
    改为 oledbda.Fill(ds)
      

  2.   

    MainForm mainform = new MainForm(); 有可能是你吧这几个窗口的名字弄错了吧
      

  3.   

    你去检查以下你的programm.cs文件 
     建议如下实现
    在program.cs 这样写
    if(FrmLogin.ShowDiagole()==DiagoleResult.OK)
    {
       FrmMain.show();
    }身边没有vs2005只能够手写 不一定正确 但是可以一试
      

  4.   

    难道是登录成功后再次跳出登录的对话框?
    可能是this.Hide 造成的,在MainForm中添加一个登录窗体的变量。
    假设登录窗体为LoginForm
    private LoginForm loginForm;MainForm增加一个构造方法;
    public MainForm(LoginFrom lForm)
    {
       this.loginForm = lForm;
    }将以下代码
    this.Hide
    MainForm mainform = new MainForm(); 
    mainform.Show();修改为
    this.Hide
    MainForm mainform = new MainForm(this); 
    mainform.Show();然后在MainFrom类的FormLoad方法中
    添加:
    loginForm.Dispose();
    将登录窗体释放掉。
      

  5.   

    可能是this.Hide   造成的
    我以前也遇见过的