【问题标题】:An unhandled exception of type 'System.Data.EvaluateException' occurred in System.Data.dllSystem.Data.dll 中出现“System.Data.EvaluateException”类型的未处理异常
【发布时间】:2016-10-05 16:39:11
【问题描述】:

C# Winforms 解决方案 - Visual Studio 2015 专业版。

大家好!当我调试我的应用程序时,打开我的表单,点击comboBoxCurso(父comboBox)并选择English,例如,然后点击DataGridView中的comboBoxModulo(子comboBox),我得到一个错误提示:

“在 System.Data.dll 中发生了“System.Data.EvaluateException”类型的未处理异常 附加信息:找不到 [English] 列。”

    private void Alunos_Load(object sender, EventArgs e)

 {

      this.tbl_cursosTableAdapter.Fill(this.bremingtonDataSet.tbl_cursos);

      this.tbl_modulosTableAdapter.Fill(this.bremingtonDataSet.tbl_modulos);

      this.tbl_turmasTableAdapter.Fill(this.bremingtonDataSet.tbl_turmas);

      this.tbl_alunosTableAdapter.Fill(this.bremingtonDataSet.tbl_alunos);

      this.tbl_alunos_subTableAdapter.Fill(this.bremingtonDataSet.tbl_alunos_sub);



      DataView dv = new DataView(bremingtonDataSet.Tables["tbl_modulos"]);

      filteredModulosBS.DataSource = dv;

 }





    private void tbl_alunos_subDataGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)

    {

        if (e.ColumnIndex == comboBoxModulo.Index)

        {

            DataGridViewComboBoxCell dgcb = (DataGridViewComboBoxCell)tbl_alunos_subDataGridView[e.ColumnIndex, e.RowIndex];

            dgcb.DataSource = filteredModulosBS;

            **Error =====> this.filteredModulosBS.Filter = "Código = "+ this.tbl_alunos_subDataGridView[e.ColumnIndex - 1, e.RowIndex].Value.ToString(); <===== Error**


        }

    }





    private void tbl_alunos_subDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)

    {

        if (e.ColumnIndex == this.comboBoxModulo.Index)

        {

            DataGridViewComboBoxCell dgcb = (DataGridViewComboBoxCell)tbl_alunos_subDataGridView[e.ColumnIndex, e.RowIndex];

            dgcb.DataSource = tblmodulosBindingSource;

            this.filteredModulosBS.RemoveFilter();

        }

    }

谁能告诉我如何更正这行代码?非常感谢您的时间和帮助。我真的很感激!

【问题讨论】:

    标签: winforms datagridview


    【解决方案1】:

    您需要将过滤条件参数用单引号 ' 括起来。

    this.filteredModulosBS.Filter = "Código = '" + this.tbl_alunos_subDataGridView[e.ColumnIndex - 1, e.RowIndex].Value.ToString() + "'";
    

    【讨论】:

    • 您好,感谢您的回复。我尝试了您的代码行,现在单击第二个组合框时出现错误:System.Data.dll 中发生“System.Data.EvaluateException”类型的未处理异常附加信息:不可能在 System.Int32 和 System.String 中执行操作 '='。
    • 根据您对“选择英语”的描述和收到的错误消息,我假设列 CódigoString 类型。根据当前的错误,我必须假设CódigoSystem.Int32。请编辑您的问题并告诉我们Código 是什么数据类型以及this.tbl_alunos_subDataGridView[e.ColumnIndex - 1, e.RowIndex].Value 包含什么。
    • 好的,我们开始吧:Código 是表 tbl_modulos 中 Module (Modulo) 的主键。 this.tbl_alunos_subDataGridView[e.ColumnIndex - 1, e.RowIndex].Value 包含学校提供的Cursos(课程)列表。
    • @JCCarmo,你需要考虑一下你正在创建的这个过滤器。如果您创建一个中间 string 变量以分配给 bindingsource 过滤器属性并设置断点以便您可以检查结果,这可能会有所帮助。 Código 将等于指定值是否有意义?我对过滤器值是什么做出了很多猜测,但根据您报告的错误,它是:Código='English'。但是,当前错误告诉您它无法将 Int32 与字符串进行比较,因此 Código 显然是一个整数。也许,你的意思是不同的专栏?
    • 我也尝试了不同的列,但它仍然给我一条错误消息,说它找不到该列...
    猜你喜欢
    • 1970-01-01
    • 2021-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多