DapperLib / Dapper

Dapper - a simple object mapper for .Net
https://www.learndapper.com/
Other
17.47k stars 3.67k forks source link

Retrieving decimal value from db causing an issue. #405

Open manohargaddam opened 8 years ago

manohargaddam commented 8 years ago

This seems like an edge case. If the decimal value with precision more than 6 digits & the value is zero, it is unable to cast it.

Interestingly If the decimal value in the DB is anything other than zero, then it is working fine.

Note 1: With decimal value precision is <= 6 everything works fine. Note 2: I had only one row in the table

Table Definition:

CREATE TABLE Table1
(
   Name varchar(20) NOT NULL,
   Rate decimal(7,7)
)

Table Data:

|Name|Rate|
|Mano|0|

When trying to fetch rows is failing.

var sql = "SELECT Name, Rate FROM Table1"
connection.Query<dynamic>(sql);

Exception

Error parsing column 2 (RATE=1 - Int16) ----> System.FormatException : Input string was not in a correct format.

In case of additional information please revert back!

Thanks!

mgravell commented 8 years ago

What does the object (class) look like here? It is very odd that it is claiming that this is a short (aka Int16) value - but that is what is being reported. Also: what is the RDBMS here?

manohargaddam commented 8 years ago

Class - dynamic RDBMS - Pivotal GemFire

devenliu commented 4 years ago

Hello!

I also encountered the same problem as you. But the difference is that the method I am calling is connection.ExecuteScalar<int>("SELECT colname ", param),

and then an exception is reported System.FormatException : Input string was not in a correct format.

By tracking Dapper's source code I found that my SQL returned an empty string, and Dapper would convert it to an int, which caused this exception. You should check the real result of your SQL return.

The location where Dapper reports error is Dapper.SqlMapper.cs (line 2941). Returns the location of the SQL execution result in Dapper.SqlMapper.cs (line 2825).

I hope my answer will help you a little. (My English is very bad, this comment was translated by Google, may not be well understood)