" '可能System.DateTime' '
client_group_details.Add(new ClientGroupDetails(
reader.GetString(Col2Index),
reader.GetString(Col3Index)));
:
Getting "This method or property cannot be called on Null values" error
は、私は、次のコードに問題がありました
ここで次のエラーが発生しました:
Data is Null. This method or property cannot be called on Null values.
この問題は、次のコードを使用して解決されました:例があるように私は今、GetDateTime
とGetInt32
と同様の問題を抱えている
client_group_details.Add(new ClientGroupDetails(
reader.IsDbNull(Col2Index) ? null : reader.GetString(Col2Index),
reader.IsDbNull(Col3Index) ? null : reader.GetString(Col3Index)));
を:
client_group_details.Add(new ClientGroupDetails(
reader.GetString(Col2Index),
reader.GetString(Col3Index),
reader.GetDateTime(Col4Index)));
私はこの問題を解決するには、次を使用してみましたが、
:それはそれはエラーになりますclient_group_details.Add(new ClientGroupDetails(
reader.IsDbNull(Col2Index) ? null : reader.GetString(Col2Index),
reader.IsDbNull(Col3Index) ? null : reader.GetString(Col3Index),
reader.IsDbNull(Col2Index) ? null : reader.GetDateTime(Col4Index)));
動作しませんでした
Compiler Error Message: CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between '<null>' and 'System.DateTime'
ソリューションを検索した後、私は見つけました:Nullable type issue with ?: Conditional Operator。しかし、私がそのコードを使用しようとすると、私は) expected
を得続けます。
どうすればこの問題を解決できますか?
あなたの括弧を数えます。あなたは右の敬けんよりも多くの敬虔を残しています。 –
')expected'エラーの原因となった、使用しようとしたコードを投稿してください。これは、簡単に修正できる単純な構文エラーです。 – phoog
ジョン・サンダースの指摘のおかげで、私はポイントを完全に逃しました。回答が削除されました。 – Almo