I built some application to convert data from oracle to mongodb. the application works fine, until some error occurred. the error is Specified cast is not valid
.
I tried to check the data to oracle, and I found some records have field that value is 1.4211E-14
.
I use OracleDataReader
for receiving the value. I've tried to convert it to decimal using this code:
OracleDataReader reader = command.ExecuteReader();
...
decimal value = 0;
if (decimal.TryParse(reader.GetString(i), NumberStyles.Float, CultureInfo.InvariantCulture, out value))
document.Set(reader.GetName(i), Convert.ToDouble(value));
else {
var v = reader.GetDecimal(i) / (decimal)1000000;
document.Set(reader.GetName(i), (float) v);
}
or even this:
document.Set(reader.GetName(i), Convert.ToString(reader.GetDecimal(i)));
the exception still occurred. what should I do to save the 1.4211E-14
as numeric data in mongodb?
I cannot save the value directly to mongodb because mongo didn't recognize decimal value.
Thanks in advance.
I got stuck I didn't get any solution yet. So I made changes directly on the query. cast the field as string, and then convert it to double in C#
SELECT ..., TO_CHAR(a_field) as a_field FROM table;
and then
OracleDataReader reader = command.ExecuteReader();
...
var field = reader.GetName(i);
if (field.equals(a_field) {
document.Set(field, Convert.ToDouble(reader.GetString(i)));
}
....
and this one works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.