如何修复错误:附加信息:找不到列? [英] How to fix error : additional information: cannot find column ?

查看:166
本文介绍了如何修复错误:附加信息:找不到列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在尝试搜索位于Form2(SearchWindow.cs)中的文本框中的值,位于Form1中的datagridview中( frPlanMain.cs)。

问题是,当我加载.xls文件并输入datagrid视图中找到的值时,我得到以下错误:

类型为'  System.Data.EvaluateException'的未处理异常 in  System.Data.dll 

附加信息:找不到列[NrFir]。





事情就是我在datagridview中添加了列标题,他们在excel文件中引用了F1到F22列。



Form1的代码是:



 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Windows.Forms;
使用 System.Data.OleDb;

命名空间 Plan_de_lucru_1._0
{
public partial class frPlanMain:Form
{

public SearchWindow frm2;

public frPlanMain()
{
InitializeComponent();
}

private void frPlanMain_Load( object sender,EventArgs e)
{

}

private void GoButton_Click( object sender,EventArgs e){
string constr = Provider = MicroSoft.Jet.OLEDB.4.0; Data Source = + locTBox.Text + ;扩展属性= \Excel 8.0; HDR = NO; \ ;;
OleDbConnection con = new OleDbConnection(constr);
OleDbDataAdapter sda = new OleDbDataAdapter( 选择*来自[ + shTBox.Text + $],con);
DataTable dt = new DataTable();
sda.Fill(dt);
CleanupDataTable(dt); // 在将dgv绑定到dt之前调用清理
dGVPlan.DataSource = dt;
new SearchWindow( this )。Show();
}

private void CleanupDataTable(DataTable dt){
if (dt.Rows.Count == 0
返回;
var headerRow = dt.Rows [ 0 ];
var columns = headerRow.ItemArray;
// 1.给出正确的列名
for int i = 0 ,l = columns.Length; i < l; i ++)
dt.Columns [i] .Namespace = columns [i] .ToString();
// 2.从结果中删除标题行
dt.Rows卸下摆臂(headerRow);
}
}
}





Form2的代码是:

 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Windows.Forms;

命名空间 Plan_de_lucru_1._0
{
public partial class SearchWindow:表单
{
public frPlanMain refTofrPlanMain;

public SearchWindow(frPlanMain f) // <<编辑在这里
{
refTofrPlanMain = f;
InitializeComponent();
}

private void SearchButtonW_Click( object sender,EventArgs e)
{
BindingSource bs = new BindingSource();
bs.DataSource = refTofrPlanMain.dGVPlan.DataSource;
bs.Filter = NrFir如'%' + searchTBoxW.Text + %'; // < - 错误位于此处
refTofrPlanMain.dGVPlan.DataSource = bs;


}
}
}





什么我试过了:



我试过了:

- 在错误位置的列名称处添加[]。

- 更改列名。

- 参考另一列。

- 删除列的referance并搜索到处。

解决方案

,con);
DataTable dt = new DataTable();
sda.Fill(dt);
CleanupDataTable(dt); // 在这里调用清理,在将dgv绑定到dt之前
dGVPlan.DataSource = dt;
new SearchWindow(这个)。Show();
}

private void CleanupDataTable(DataTable dt){
if (dt.Rows.Count == 0
return < /跨度>;
var headerRow = dt.Rows [ 0 ];
var columns = headerRow.ItemArray;
// 1.给出正确的列名
for int i = 0 ,l = columns.Length; i < l; i ++)
dt.Columns [i] .Namespace = columns [i] .ToString();
// 2.从结果中删除标题行
dt.Rows卸下摆臂(headerRow);
}
}
}





Form2的代码是:

 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Windows.Forms;

命名空间 Plan_de_lucru_1._0
{
public partial class SearchWindow:表单
{
public frPlanMain refTofrPlanMain;

public SearchWindow(frPlanMain f) // <<编辑在这里
{
refTofrPlanMain = f;
InitializeComponent();
}

private void SearchButtonW_Click( object sender,EventArgs e)
{
BindingSource bs = new BindingSource();
bs.DataSource = refTofrPlanMain.dGVPlan.DataSource;
bs.Filter = NrFir如'%' + searchTBoxW.Text + %'; // < - 错误位于此处
refTofrPlanMain.dGVPlan.DataSource = bs;


}
}
}





什么我试过了:



我试过了:

- 在错误位置的列名称处添加[]。

- 更改列名。

- 参考另一列。

- 删除列的referance并搜索到处。


Hello,

I am trying to search a value that i imput in a textbox located in Form2 (SearchWindow.cs), in a datagridview located in Form1 (frPlanMain.cs).
Problem is that when i load the .xls file and imput a value found in the datagrid view i get the following error :

An unhandled exception of type 'System.Data.EvaluateException' occurred in System.Data.dll

Additional information: Cannot find column [NrFir].



Thing is that i added column headers in the datagridview and they referance to column F1 to F22 in a excel file.

The code for Form1 is :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Plan_de_lucru_1._0
{
    public partial class frPlanMain : Form
    {

        public SearchWindow frm2;

        public frPlanMain()
        {
            InitializeComponent();
        }

        private void frPlanMain_Load(object sender, EventArgs e)
        {
        
        }

    private void GoButton_Click(object sender, EventArgs e) {
        string constr = "Provider = MicroSoft.Jet.OLEDB.4.0; Data Source=" + locTBox.Text + ";Extended Properties =\"Excel 8.0; HDR=NO;\";";
        OleDbConnection con = new OleDbConnection(constr);
        OleDbDataAdapter sda = new OleDbDataAdapter("Select * From [" + shTBox.Text + "$]", con);
        DataTable dt = new DataTable();
        sda.Fill(dt);
        CleanupDataTable(dt); // call the cleanup here, before binding dgv to dt
        dGVPlan.DataSource = dt;
        new SearchWindow(this).Show();
    }

    private void CleanupDataTable(DataTable dt) {
        if(dt.Rows.Count == 0)
            return;
        var headerRow = dt.Rows[0];
        var columns = headerRow.ItemArray;
            // 1. give the right column names
            for (int i = 0, l = columns.Length; i < l; i++)
                dt.Columns[i].Namespace = columns[i].ToString();
        // 2. remove the header row from the result
        dt.Rows.Remove(headerRow);
    }
}
}



The code for Form2 is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Plan_de_lucru_1._0
{
    public partial class SearchWindow : Form
    {
        public frPlanMain refTofrPlanMain;

        public SearchWindow(frPlanMain f) //<<Edit made here 
        {
            refTofrPlanMain = f;
            InitializeComponent();
        }

        private void SearchButtonW_Click(object sender, EventArgs e)
        {
            BindingSource bs = new BindingSource();
            bs.DataSource = refTofrPlanMain.dGVPlan.DataSource;
            bs.Filter = "NrFir like '%" + searchTBoxW.Text + "%'"; // <--Error is located here
            refTofrPlanMain.dGVPlan.DataSource = bs;


        }
    }
    }



What I have tried:

I have tryed:
- To add [] at the column name at the error location.
- Change the column name.
- Referance to another column.
- Remove the referance to the column and search everywhere.

解决方案

", con); DataTable dt = new DataTable(); sda.Fill(dt); CleanupDataTable(dt); // call the cleanup here, before binding dgv to dt dGVPlan.DataSource = dt; new SearchWindow(this).Show(); } private void CleanupDataTable(DataTable dt) { if(dt.Rows.Count == 0) return; var headerRow = dt.Rows[0]; var columns = headerRow.ItemArray; // 1. give the right column names for (int i = 0, l = columns.Length; i < l; i++) dt.Columns[i].Namespace = columns[i].ToString(); // 2. remove the header row from the result dt.Rows.Remove(headerRow); } } }



The code for Form2 is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Plan_de_lucru_1._0
{
    public partial class SearchWindow : Form
    {
        public frPlanMain refTofrPlanMain;

        public SearchWindow(frPlanMain f) //<<Edit made here 
        {
            refTofrPlanMain = f;
            InitializeComponent();
        }

        private void SearchButtonW_Click(object sender, EventArgs e)
        {
            BindingSource bs = new BindingSource();
            bs.DataSource = refTofrPlanMain.dGVPlan.DataSource;
            bs.Filter = "NrFir like '%" + searchTBoxW.Text + "%'"; // <--Error is located here
            refTofrPlanMain.dGVPlan.DataSource = bs;


        }
    }
    }



What I have tried:

I have tryed:
- To add [] at the column name at the error location.
- Change the column name.
- Referance to another column.
- Remove the referance to the column and search everywhere.


这篇关于如何修复错误:附加信息:找不到列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆