Format Combobox value pulled from SQL database (LINQ) in C# Project (WPF)

Asked

Viewed 127 times

3

I need some help with the code below... I need to make the Float value pulled from the SQL Database in the Brazilian format of the Real Number Set in a C# (WPF) project in a Combobox (as Double). That is, bring it as String in Intemssource and not stay in this format "0.000", but in this "0,000".

Code:

var query_Fardo = from f in oDB.tabProdutos 
                  where f.Codigo == Convert.ToInt32(txtCodigoApontaPrd.Text) 
                  select f.Fardo;
CmBox_FardoApontaPrd.ItemsSource = query_Fardo;
CmBox_FardoApontaPrd.ItemStringFormat = "0,000";//Não funciona

Grateful for the support...

1 answer

0


I didn’t understand if I wanted the guy to look like Double, but it follows a transforming response to string:

var query_Fardo = from f in oDB.tabProdutos 
                  where f.Codigo == Convert.ToInt32(txtCodigoApontaPrd.Text) 
                  select f.Fardo.ToString("#,###.###");

With that, it wouldn’t be necessary

Cmbox_fardoapontaprd.Itemstringformat = "0,000";

  • Since Cmbox_fardoapontaprd is a String you need to convert Float to String... But it needs to appear as Double (Real number)... The value is type "0,000" ex.: 1,020; 1,920... Understand?

  • This f.Fardo.Tostring("#,###.###") method has no SQL supported conversions.

  • oDB is of what type?

  • Use LINQ to SQL...in Table tableProducts the Bale column is Float... And so pull: Trssystemdataclassesdatacontext oDB = new Trssystemdataclassesdatacontext()

  • Does that help? I don’t understand when you ask the type oDB... I use SQL Server

  • Try to convert into a list with this issue your previous: var oProdutos = (from Selecao in oDB.tabProdutos orderby Selecao.Descricao select Selecao).ToList<tabProduto>(); then try to .ToString("#,###.###");

  • Didn’t work out! :(

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.