SQLServer int 字段。值有时为空。DataAdapter 填充数据集 OK 并可以在 DatagridView 中显示数据 OK。
尝试以编程方式从数据集中检索数据时,Dataset 字段检索代码会引发 StronglyTypedException 错误。
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public int curr_reading {
get {
try {
return ((int)(this[this.tableHistory.curr_readingColumn]));
}
catch (global::System.InvalidCastException e) {
throw new global::System.Data.StrongTypingException("The value for column \'curr_reading\' in table \'History\' is DBNull.", e);
}
通过在 get 访问器中检查 DBNull 并返回 null 解决了这个问题,但是......当数据集结构被修改(仍在开发中)时,我的更改(不出所料)消失了。
处理这种情况的最佳方法是什么?看来我被困在数据集级别处理它。是否有某种属性可以告诉自动代码生成器保留更改?