Good day! Saw a lot of questions about this but did not find the answer

here is my code

connection.Open(); OracleCommand command = connection.CreateCommand(); string sql="select t2.NAME, Round((cast(localtimestamp as date) - cast(t4.CREATED as date))*24*60,2) ,t3.NAME,localtimestamp from MFSTRANSPORTORDER t1 left join MFSTRANSPORTUNIT t2 on t2.ID=t1.TRANSPORTUNIT_ID left join MFSSTORAGELOCATION t3 on t3.ID=t2.STORAGELOCATION_ID left join MFSTRANSPORTORDERREQUEST t4 on t2.ID=t4.TRANSPORTUNIT_ID where t3.NAME is NOT NULL"; command.CommandText = sql; OracleDataReader reader = command.ExecuteReader(); var lst = new List<Data>(); if (reader.HasRows) { while(reader.Read()){ var row = new Data(); row.Name = reader.GetString(0); if(!reader.IsDBNull(1)) row.Time = reader.GetDouble(1); row.Place = reader.GetString(2); row.dt = reader.GetDateTime(3); } int g = lst.Count; Data []temp=new Data[g]; temp = lst.ToArray(); } connection.Close(); 

In the query string I'm interested in the second column.

 Round((cast(localtimestamp as date) - cast(t4.CREATED as date))*24*60,2) 

When doing

 row.Time = reader.GetDouble(1); 

an error

 SystemInvalidCastException: Specified cast is not valid 

This field should contain a number of 2.45

How to remove this error?

    1 answer 1

    How about finding out the real type of value, and then calling the appropriate method?

     reader.GetFieldType(1) 

    Perhaps there is a decimal:

     reader.GetDecimal(1) 
    • Really decimal. Thank you - user3216530
    • @ user3216530 is not for nothing! - andreycha