对于未定义为 System.String 的列,唯一有效的值是(引发异常)

问题描述:
对于未定义为 System.String 的列,唯一有效的值是(引发异常)。
For columns not defined as System.String, the only valid value is (Throw exception).


设置NullValue为(Empty) or (Null)会出现以下提示:



解决方案:
这是一个Bug,在微软的网站上有详细的描述(English):
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=93616
VS2005中不会修复该Bug。
具体的解决步骤如下(English):
http://blogs.msdn.com/smartclientdata/archive/2005/08/13/NullValueForTypedDataSet.aspx
关键的内容我翻译如下:


示例一: 如果有一个数据类型是System.Data.DataSet的列,你想把它的NullValue设置为Nothing。你可以用文本编辑器(比如XmlEditor)打开数据集文件,找到此列的msprop:nullValue ,把它替换成msprop:nullValue="_null". 如果找不到此列的msprop:nullValue 属性,就添加msprop:nullValue="_null".
修改之后,整列看起来和下面的差不多:
<xs:element name="Column1" type="..." msprop:nullValue="_null"   .../>
保存数据集文件,确保没有编译错误,并且后置代码被正确地生成。


示例二: 如果有一个数据类型是Int32 的列,你想把它的 "ABC" 设置为-1。你可以用文本编辑器(比如XmlEditor)打开数据集文件,找到此列的msprop:nullValue ,把它替换成msprop:nullValue="-1"。如果找不到此列的msprop:nullValue 属性,就添加msprop:nullValue="-1"。


注意:
如果你保存数据集文件之后遇到以下错误:

Custom tool error: Failed to generate code. Failed to generate code. Exception has been thrown by the target of an invocation.
那说明你的NullValue 无效(比如,对于一个整形列, NullValue设置成 "ABC" ),你需要重新修改NullValue为有效的值。
提示:当你编辑数据集文件时,要正确使用下面的保留值。

msprop:nullValue="_empty" -- (Empty)

msprop:nullValue="_null" -- (Nothing)

msprop:nullValue="_throw" -- (Throw exception)

 

示例三:

<xs:element name="IntegerColumn" msprop:nullValue="-1" msdata:ReadOnly="true" msdata:Caption="IntegerColumn" msprop:Generator_UserColumnName="IntegerColumn" msprop:Generator_ColumnPropNameInRow="IntegerColumn" msprop:Generator_ColumnVarNameInTable="columnIntegerColumn" msprop:Generator_ColumnPropNameInTable="IntegerColumnColumn" type="xs:int" minOccurs="0" /> 

<xs:element name="BoolColumn" msprop:Generator_UserColumnName="BoolColumn" msprop:nullValue="0" minOccurs="0" msprop:Generator_ColumnPropNameInRow="BoolColumn" msprop:Generator_ColumnVarNameInTable="columnBoolColumn" msprop:Generator_ColumnPropNameInTable="BoolColumnColumn" type="xs:boolean" />

参考:

http://aspalliance.com/1367_Typed_Dataset_and_its_Usages.8

http://aspalliance.com/1367_Typed_Dataset_and_its_Usages.all

http://blog.evolvedsoftwarestudios.com/2008/03/18/allow-null-values-to-be-returned-from-strongly-typed-datasets/

作者:lam815@tom.com

相关文章

引言 本文从Linux小白的视角, 在CentOS 7.x服务器上搭建一个...
引言: 多线程编程/异步编程非常复杂,有很多概念和工具需要...
一. 宏观概念 ASP.NET Core Middleware是在应用程序处理管道...
背景 在.Net和C#中运行异步代码相当简单,因为我们有时候需要...
HTTP基本认证 在HTTP中,HTTP基本认证(Basic Authenticatio...
1.Linq 执行多列排序 OrderBy的意义是按照指定顺序排序,连续...