try
            {                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                login frm = new login(); 
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    Application.Run(new FrmMain()); 
                }
                else
                {
                    Application.Exit();
                }
            }
            catch (Exception ex) //此处抛的异常 “字符串格式不正确”
            {
                MessageBox.Show(ex.Message.ToString(), "系统登录", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                Application.Exit();
            }

解决方案 »

  1.   

    frm窗体启动时如果没做异常处理的话,应该是frm窗体启动时抛出的错误。
      

  2.   

    查看一下frm的构造函数和loaded事件等,可以trackin一下
      

  3.   

    应该是你的登录窗口login frm中的错误,查查看
      

  4.   

    FrmMain 加载 事件 看下 是不是有类型转换的东东!!!
      

  5.   

    DataHelper db = new DataHelper();
                    string name = Convert.ToString(TxtName.Text.Trim());
                    string pwd = Convert.ToString(TxtPwd.Text.Trim());
                    try
                    {
                    bool results = db.getCount("select * from admin where username='" + name + "'and userpwd='" + pwd + "'");
                    if (results == true)
                    {
                        user.Name = name;
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        MessageBox.Show("您无权查看!!!", "系统登录", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    }
                    catch(Exception ex)//从此处抛出异常 “字符串”格式不正确
                    {
                       MessageBox.Show(ex.Message.ToString());
                    }
    那就应该是这一行了 
      

  6.   

    string name = Convert.ToString(TxtName.Text.Trim());
    string pwd = Convert.ToString(TxtPwd.Text.Trim());
    写成
    string name = TxtName.Text.Trim();
    string pwd = TxtPwd.Text.Trim();//当然,这个不是错误..getCount这个怎么定义的?断掉调试下,看看具体是哪行出错了
      

  7.   

    "'and
    'and  当中空一格
      

  8.   

    应该sql 语句那一行出错了 返回的类型 方法写的都对 
      

  9.   

     db.getCount返回值估计返回的不是bool类型
      

  10.   

    "select * from admin where username='" + name + "' and userpwd='" + pwd + "'");
                                                      -
      

  11.   

     name + "' and userpwd
    //and前应该有空格
      

  12.   

    还是不行 只要有sql语句 返回的结果 也对 就是执行到if(results == true) 抛异常   
      

  13.   

    db.getCount 函数的返回类型对么?
      

  14.   

    bool results = db.getCount("select * from admin where username='" + name + "'and userpwd='" + pwd + "'");
    这行设置断点..
    调试时监测results的值,还是在取值是发生异常,getCount怎么定义的?
      

  15.   

    admin可能是sql关键字("select * from [admin] where username='" + name + "'and userpwd='" + pwd + "'")这样试试