System.ArgumentException柱<的ColumnName>不属于表 [英] System.ArgumentException Column <ColumnName> does not belong to table

查看:633
本文介绍了System.ArgumentException柱<的ColumnName>不属于表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的ColumnName>

我在数据表中,其名称 System.ArgumentException列&LT访问的一个DataColumn值时,有一个问题;不属于表发生的一些列。然而列存在于数据库中,但使用不同的情况下。我以为数据表中的列名不区分大小写。任何1人有任何想法,为什么我得到这一点。在不同的机器上这code是工作的罚款。我不认为这有什么事与SQL Coallation但在这种情况下,coallation相同的两个SQL服务器。

  vpg_awardtype =行[vpg_awardtype];
vpg_eventcount =行[vpg_eventcount];
 

如果我将其更改为以下,然后它的工作:

  vpg_awardtype =行[Vpg_AwardType];
vpg_eventcount =行[Vpg_EventCount];
 

解决方案

我已经解决了。基本上当一个DataTable包含的名字只在案例即不同的一个呈三角列名的 AwardType awardType 有相同的列名,但只有在拼写情况不同。如果这样的碰撞发生里一个DataTable这使得访问所有的数据表中的列区分大小写。

在我的情况下,有一些联接由开发应用来获得数据的数据表。但是列数不过滤,遗憾的是在2个不同的表列名之一是呈三角但写不同的情况。我没能注意到,因为数据表是巨大的。最后,我发现这个硬盘的方式。因此别名为我工作列名之一。

I am having a problem when accessing a DataColumn value in datatable with its name the System.ArgumentException Column <ColumnName> does not belong to table occurs for some of the columns. However the column exists in the database but with a different case. I thought DataTable column names are case insensitive. Any 1 got any idea why I am getting this. On a different machine this code is working fine. I don't think it has any thing to do with SQL Coallation but in this case the coallation are same on both SQL servers.

vpg_awardtype = row["vpg_awardtype"];
vpg_eventcount = row["vpg_eventcount"];

If i change it to the following then it's working:

vpg_awardtype = row["Vpg_AwardType"];
vpg_eventcount = row["Vpg_EventCount"];

解决方案

I've resolved it. Basically when a DataTable contains a simillar column name whose name is only different in Case i.e AwardType and awardType are same column names but only different in spelling case. If such a collision occur inside a DataTable This makes the access to all DataTable columns as case sensitive.

In my case there was some joins applied by a developer to get the data in the datatable. However the number of columns were not filtered and unfortunately in 2 different tables one of the column name was simillar but written with different case. I wasn't able to notice that because the datatable was huge. Finally I found this out the hard way. Hence aliasing one of the column name worked for me.

这篇关于System.ArgumentException柱&LT;的ColumnName&GT;不属于表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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