“一旦列有数据就无法更改其数据类型” Visual Studio 2005 数据集设计器中的错误
我在 VisualStudio 2005 中有一个数据集。我需要将其中一个数据表中的列的数据类型从 System.Int32
更改为 System.Decimal
。 当我尝试更改数据集设计器中的数据类型时,我收到以下错误:
属性值无效。 无法更改列的数据类型一次 它有数据。
根据我的理解,这应该更改数据集架构中的数据类型。 我不明白如何有任何数据会导致此错误。
有人有什么想法吗?
I've got a DataSet in VisualStudio 2005. I need to change the datatype of a column in one of the datatables from System.Int32
to System.Decimal
. When I try to change the datatype in the DataSet Designer
I receive the following error:
Property value is not valid. Cannot change DataType of a column once
it has data.
From my understanding, this should be changing the datatype in the schema for the DataSet. I don't see how there can be any data to cause this error.
Does any one have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(6)
- 在可视化设计器中关闭数据集
- 右键单击数据集,选择
打开方式...
- 选择
XML(文本)编辑器
- 在 XML 中找到该列,它将在您的数据集中看起来像这样:
<xs:element name="DataColumn1"
msprop:Generator_ColumnVarNameInTable="columnDataColumn1"
msprop:Generator_ColumnPropNameInRow="DataColumn1"
msprop:Generator_ColumnPropNameInTable="DataColumn1Column"
msprop:Generator_UserColumnName="DataColumn1"
type="xs:int"
minOccurs="0" />
- 将
type="xs:int"
更改为type="xs:decimal"
- 保存并关闭 XML 编辑器
- 您可能需要再次右键单击数据集并选择
运行自定义工具
对于那些通过 Google 发现这一点的人来说,您的情况略有不同,您的表已获取数据并且添加了一个新列(像我一样),如果您创建该列并在单独的语句中设置数据类型,您也会得到相同的异常。 但是,如果您在同一条语句中执行此操作,则效果很好。
因此,不要这样做:
var column = myTable.Columns.Add("Column1");
column.DataType = typeof(int); //nope, exception!
这样做:
var column = myTable.Columns.Add("Column1", typeof(int));
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
这是一个老问题,但在 VS 2019 中仍然可能发生
解决方案:
现在应该可以毫无问题地更改类型。
Its an old Question but it still can happen at VS 2019
Solution:
Now it should be possible to change the type without any problem.