' and ' System.DateTime'”错误消息-6ren"> ' and ' System.DateTime'”错误消息- 很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1-6ren">
gpt4 book ai didi

c# - 获取 "no implicit conversion between ' ' and ' System.DateTime'”错误消息

转载 作者:太空狗 更新时间:2023-10-30 00:01:52 25 4
gpt4 key购买 nike

<分区>

在上一个问题中:

Getting "This method or property cannot be called on Null values" error

我遇到了以下代码的问题:

client_group_details.Add(new ClientGroupDetails(
reader.GetString(Col2Index),
reader.GetString(Col3Index)));

我在哪里遇到以下错误:

Data is Null. This method or property cannot be called on Null values.

此问题已使用以下代码解决:

client_group_details.Add(new ClientGroupDetails(
reader.IsDbNull(Col2Index) ? null : reader.GetString(Col2Index),
reader.IsDbNull(Col3Index) ? null : reader.GetString(Col3Index)));

我现在对 GetDateTimeGetInt32 也有类似的问题,例如:

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

我该如何解决这个问题?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com