zoukankan      html  css  js  c++  java
  • C# 错误集锦

    本文内容主要记录本人学习过程中遇到的错误,其中不乏有一些低级错误,为了牢记以免再次犯错特意记录,不要笑话哈;

    1.“System.TypeInitializationException”类型的未经处理的异常在 LoginDAL.dll 中发生其他信息: “sqlHelper.sqlHelper”的类型初始值设定项引发异常;

    问题原因:App.config文件中配置的connectionString.name="conn"与代码中读取配置文件ConfigurationManager.ConnectionStrings["connStr"]提取的索引名称不一致;

    解决办法:保持一致;

    2.阅读器关闭时尝试调用Read无效;

    问题原因:①在获取SqlDataReader时创建连接使用了using();②在Reader SqlDataReader前关闭了链接或Reader

    解决办法:去掉using,在Reader之前不要关闭Reader;

    3.Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery, DbRawSqlQuery) is not supported. Instead populate a DbSet with data, for example by calling Load on the DbSet, and then bind to local data. For WPF bind to DbSet.Local. For WinForms bind to DbSet.Local.ToBindingList(). For ASP.NET WebForms you can bind to the result of calling ToList() on the query or use Model Binding......

    private void barBtnQuery_ItemClick(object sender, HuanSi.XtraBars.ItemClickEventArgs e)
    {
         using(var db=new DBModel())
         {
              var result = from s in db.Students 
                                 select new { s.sName,s.iAge};
               gridControl1.DataSource = result.ToList();//不加ToList()会报错
               gridView1.PopulateColumns();
         }
    }

     4.服务容器中已存在服务 System.Windows.Forms.Design.IEventHandlerService 参数名: serviceType 

    参考链接:https://blog.csdn.net/zibinghanmo/article/details/41409095 ;

    项目中有几个功能窗体界面几乎相同,然后就想开发一个父类窗体用来继承,但是在继承时报了如题错误,上面的参考链接很详细,需要修改3个位置,但是我实操后,发现只需要修改form_load下的内容即可;

    原来的代码:

    private void Form_Load(...)
    {
      btnPass.BackColor = Color.Green;
      btnReject.BackColor = Color.Red;
      btnWaive.BackColor = Color.Yellow;
    } 

    解决方案如下:

    在基类的Form1中进行如下修改:

    private void Form_Load(...)
    {
      if(!DesignMode)
      {
        //代码放在这儿
        btnPass.BackColor = Color.Green;
        btnReject.BackColor = Color.Red;
        btnWaive.BackColor = Color.Yellow;
      }
    }
    

     在修改之后重新生成解决方案会发现依然显示报错,不能正常显示子类窗口,这时只需要把解决方案重新打开即可,如果确实还不行就重启系统;如果还是不行就参考我发的那个链接,修改那3处,然后重开解决方案;反正我是修改了一处form_load后重启解决方案就解决了;

  • 相关阅读:
    springEL单引号默认值
    vscode支持c99标准
    Error loading class 'solr.HMMChineseTokenizerFactory'
    spring security通过UserDetailsService方式当找不到用户时兼容i18n方法
    springboot普通类中获取i18对应的值
    docker-compose安装后执行报错
    springboot日志
    mysql登录报错:mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
    springboot统一ajax返回数据格式,并且jquery ajax success函数修改
    spring security jquery ajax重定向问题解决
  • 原文地址:https://www.cnblogs.com/allen0/p/9495950.html
Copyright © 2011-2022 走看看