0
Hello, everyone. I’m having trouble retrieving the numerical values from the database in my Datagridview
already formatted (including commas and dots).
The code that gets the data through a process and adds in my Datagridview
is:
string sql = "SELECT * FROM BUSCA_DETALHES_CARTEIRA(1, '1-JAN-2017', '31-JAN-2019', '1', 'N')";
using (FbCommand command_ObtemDadosRel = new FbCommand(sql, ConexaoAoBanco))
{
ConexaoAoBanco.Open();
using (IDataReader reader = command_ObtemDadosRel.ExecuteReader())
{
while (reader.
dataGridView1.Rows.Add(Convert.ToDouble(reader[2]));
}
}
}
Values directly in my database are formatted already (with semicolons):
But in the Datagridview
gets like this:
The details are: I’ve tried using the conversion option for Decimal
dataGridView1.Rows.Add(Convert.ToDecimal(reader[2]));
For the command of GetTypeCode
of Reader
, returns to me that it is of the type Decimal
But I still tried Convert.ToDouble(reader[2]))
, dataGridView1.Rows.Add(reader.GetDecimal(2).ToString())
, dataGridView1.Rows.Add(reader.GetDouble(2).ToString());
and also dataGridView1.Rows.Add(reader.GetFloat(2).ToString())
only for the discharge of conscience. Both did not work.
This column of my database where I read and add in Datagridview
the records are of the type Numeric
.
How can I get the values already with commas and dots? Need to adjust something at the time of reading the data or is some property itself Datagridview
?
dataGridView1.Columns["Column1"].DefaultCellStyle.Format = "n";
– vik
Sorry to ask, but where should this code be located? At which event?
– Matheus Oliveira.
I am a beginner.
– Matheus Oliveira.