************** 异常文本 **************
System.NullReferenceException: 未将对象引用设置到对象的实例。
   在 DB.GetSqlCon() 位置 E:\应用\DormManageSystemfinal\app_code\DB.cs:行号 30
   在 DB.GetDataTable(String sql) 位置 E:\应用\DormManageSystemfinal\app_code\DB.cs:行号 73
   在 DormManageSystem.AddStudent.comboBox_lou_SelectedIndexChanged(Object sender, EventArgs e) 位置 E:\应用\DormManageSystemfinal\AddStudent.cs:行号 89
   在 System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
   在 System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
   在 System.Windows.Forms.ComboBox.WndProc(Message& m)
   在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
F5运行一点错没有  , .exe打开就有错 ,啥情况

解决方案 »

  1.   

    行号都告诉你了,那行代码中你访问量null对象
      

  2.   

    F5运行的exe和你点的exe是同一个吗?
      

  3.   


      public static SqlConnection GetSqlCon()
        {
            string ConString = System.Configuration.ConfigurationManager.ConnectionStrings["dormmanageConnectionString"].ConnectionString;        SqlConnection con = new SqlConnection(ConString);
            return con;
        }
    就这个找app.config数据连接阿
    <connectionStrings>
            <add name="dormmanageConnectionString"
                connectionString="Data Source=LBWIN7\SQL2005;Initial Catalog=manage;User ID=sa;Password=123"
                providerName="System.Data.SqlClient" />
        </connectionStrings>
      

  4.   

    确保exe目录下有你程序名称的config文件?
      

  5.   

    还是一样 , F5运行一点错没有,就生成的exe运行报这错
      

  6.   

    string ConString = System.Configuration.ConfigurationManager.ConnectionStrings["dormmanageConnectionString"].ConnectionString;//从config文件里取值,没找到config文件当然报错了
      

  7.   


    exe是生成到Debug文件夹阿, config 文件拷进去?那不也没有啊
      

  8.   

    阿  不好意思找错exe的位置了  bin/debug  下面的 exe  才是对的  ,不好意思 感谢各位!