DB テーブルから DataSet を自動的に取得する必要がありました。内部の Visual Studio ツールを使用しました。作成された何百万もの行の間で、これはアクセサー メソッドの 1 つです。
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
public string Referente {
get {
try {
return ((string)(this[this.tableCATALOGO_Cliente.ReferenteColumn]));
}
catch (global::System.InvalidCastException e) {
throw new global::System.Data.StrongTypingException("The value for column \'Referente\' in table \'CATALOGO_Cliente\' is DBNull.", e);
}
}
set {
this[this.tableCATALOGO_Cliente.ReferenteColumn] = value;
}
}
ご覧のとおり、このコードはReferente
列を参照しています。ジェネリックを取得する必要があるReferente
場合はNULL
、return
発生できない原因で例外がスローされます。returnステートメントを次のものに置き換えて問題を解決しました。
return this[this.tableCATALOGO_Cliente.ReferenteColumn] as string;
テーブルには何百もの列が含まれているため、このプロセスを自動的に行う方法を考えます (つまり、発生したDataSet
場合に例外をスローしない with アクセサー メソッドを生成しますIS NULL
)。