System.ArgumentException 列不属于表

发布于 2024-11-07 11:27:40 字数 478 浏览 0 评论 0原文

我在访问数据表中名称为 System.ArgumentException Column的 DataColumn 值时遇到问题某些列不属于表。然而,该列存在于数据库中,但大小写不同。我认为 DataTable 列名称不区分大小写。任何人都知道我为什么会得到这个。在另一台机器上,此代码运行良好。我不认为它与 SQL 联盟有任何关系,但在这种情况下,两个 SQL 服务器上的联盟是相同的。

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

如果我将其更改为以下内容,那么它就可以工作:

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

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"];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗼ふ静 2024-11-14 11:27:40

我已经解决了。基本上,当 DataTable 包含类似的列名称时,其名称仅在大小写上不同,即 AwardTypeawardType 是相同的列名称,但仅在拼写大小写上不同。如果此类冲突发生在 DataTable 内部,这会使对所有 DataTable 列的访问区分大小写。

就我而言,开发人员应用了一些联接来获取数据表中的数据。然而,列数没有被过滤,不幸的是,在两个不同的表中,其中一个列名称相似,但大小写不同。我无法注意到这一点,因为数据表很大。最后我通过艰难的方式发现了这一点。因此,别名列名之一对我有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文