Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Oracle DataReader在GetDateTime上出错_C#_Asp.net_Oracle_Datareader - Fatal编程技术网

C# Oracle DataReader在GetDateTime上出错

C# Oracle DataReader在GetDateTime上出错,c#,asp.net,oracle,datareader,C#,Asp.net,Oracle,Datareader,我有一个特定的数据行,当我试图在特定的日期列中读取“年、月和日参数描述不可表示的日期时间”时,它抛出了这个错误 我正在提取几百行数据,除了这一行,它们都可以工作。除了这个datetime列之外,我可以从这个有问题的行中提取其他列。我正在使用oracle数据读取器从数据库中获取日期时间,我可以使用Visual Studio中的监视工具检查我将要读入的行。在watch工具中,一切看起来都很好——它将我试图读入的专栏视为datetime,并具有它的所有属性 while (reader.Re

我有一个特定的数据行,当我试图在特定的日期列中读取“年、月和日参数描述不可表示的日期时间”时,它抛出了这个错误

我正在提取几百行数据,除了这一行,它们都可以工作。除了这个datetime列之外,我可以从这个有问题的行中提取其他列。我正在使用oracle数据读取器从数据库中获取日期时间,我可以使用Visual Studio中的监视工具检查我将要读入的行。在watch工具中,一切看起来都很好——它将我试图读入的专栏视为datetime,并具有它的所有属性

      while (reader.Read())
                {
                    var temp = new FCCondition();
                    temp.CaseID = reader.GetString(0);                      
                    temp.Statute = reader.GetString(1);
                    if (!reader.IsDBNull(2))
                        temp.DueDate = reader.GetDateTime(2);
                    if (!reader.IsDBNull(3))
                        temp.HoursAssigned = reader.GetInt32(3);
                    if (!reader.IsDBNull(4))
                        temp.HoursCompleted = reader.GetInt32(4);
                    temp.JWConditionID = reader.GetString(5);
                    if (!reader.IsDBNull(6))                      
                            temp.StartDate = reader.GetDateTime(6);                                                                          
                    if (!reader.IsDBNull(7))
                        temp.StatusDate = reader.GetDateTime(7);
                    if (temp.DueDate <= temp.StartDate)
                        temp.DueDate = temp.StartDate.AddMonths(18);                        
                    FCConditionsList.Add(temp);
                }
            }
while(reader.Read())
{
var temp=新的FCCondition();
temp.CaseID=reader.GetString(0);
临时规约=reader.GetString(1);
如果(!reader.IsDBNull(2))
temp.DueDate=reader.GetDateTime(2);
如果(!reader.IsDBNull(3))
temp.HoursAssigned=reader.GetInt32(3);
如果(!reader.IsDBNull(4))
temp.HoursCompleted=reader.GetInt32(4);
temp.JWConditionID=reader.GetString(5);
如果(!reader.IsDBNull(6))
temp.StartDate=reader.GetDateTime(6);
如果(!reader.IsDBNull(7))
temp.StatusDate=reader.GetDateTime(7);

如果(temp.DueDate我怀疑
GetDateTime
调用不需要AM/PM符号?因此,它可能无法将其识别为有效的日期/时间。请尝试以下操作:

if (!reader.IsDBNull(6)) {
  var temporaryDate = reader.GetValue(6).ToString();

  DateTime outDate;
  if (DateTime.TryParseExact(temporaryDate, "M/dd/yyyy h:mm:ss tt", null, DateTimeStyles.None, out outDate))
  {
    temp.StartDate = outDate;
  }
}
编辑:今天我自己也遇到了同样的问题,并以不同的方式解决了它……我使用的是Oracle Data access托管客户端

if (!reader.IsDBNull(6)) {
  var tempDate = reader.GetOracleDate(6);
  temp.StartDate = new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, tempDate.Hour, tempDate.Minute, tempDate.Second);
}

我认为第6列和第7列可能是相反的。错误应该发生在DueDate上,因为它是null。@jdweng如果是这样的话,它应该跳过那行代码,因为我有DBNull检查,对吗?当你接近创建一个异常时,你会发现你发布的代码抛出异常的原因。你可以从一个cre根据“从双通道选择sysdate”设置读卡器或者您可以开始删除现有函数中的代码。Net不允许日期时间为空。而默认的1/1/01用于Net中的日期时间。我不确定Oracle是如何工作的。您绝对肯定是这一行吗?我知道Oracle对数字很有趣。我有点惊讶您没有出错或者使用(3)和(4),其中显示为十进制,但您似乎能够使用GetInt32进行读取。如果您不介意我问一下,这些字段的Oracle数据类型是什么(我在Oracle中总是使用数字(9,0)表示.Net ints)。但它处理的是GetDateTime(2)还有AM?两者都显示为对象Sysem.DateTime。所以我不认为这与AM/PM有任何关系?这只是一种预感,GetDateTime(2)返回了一个不同格式的日期,很容易理解12/31-但6/7的日期是谁都猜不到的。。。