Linq command to bring up a decimal query C#

Asked

Viewed 168 times

2

I’m having trouble understanding how to bring a query from textbox of a column where the field is decimal?

if (txtNomePesquisar.Text.Equals(""))
{
    MessageBox.Show("O que você procura? ");
}
else 
{       
    var clientes = cc
          .TB_CLIENTEs.Where(c => c.NOM_CLIENTE.Contains(txtNomePesquisar.Text)).ToList();
    dgvCliente.DataSource = clientes;
}

if (txtTelPesquisar.Text.Equals(""))
{

/// a mensagem é  'decimal' does contain a definition for (Contains) and...
/// e fala de IQueryable mais não sei utilizar ainda
/// 
    var clientes = cc.TB_CLIENTEs
          .Where(c => c.TEL_CLIENTE.Contains(txtTelPesquisa.Text)).ToList();
}
  • which field is decimal?

  • var clients = cc.Tb_clients . Where(c => c.TEL_CLIENTE.Contains(txtTelPesquisa.Text)). Tolist();

  • this is the decimal field TEL_CLIENTE

  • So I made an answer, see if that’s what you need?

  • Thank you, I’m trying because when I search with this code it does not bring value more if I type the number 1 it brings the record that has only the number 1 those that has more than one number for example : 44334, it does not bring results there I am checking what can be.

  • What do you need?

  • what I’m having difficulty is I have 2 search fields when I click the search button it can bring the list by NAME or PHONE in SQL I know how to do more in C# I’m not getting the way I can bring the NAME was as the code above is and I separated the PHONE because I couldn’t put it together. What I need is to bring the list either with the PHONE or NAME when clicked on the SEARCH button... I’m almost changed the data type of the phone field to scan if I can’t.

  • Phone is good to be in varchar friend... if put decimal in my opinion have a future mistake.

  • I figured I’ll do it myself since it’s so complicated. Thanks for the help.

Show 4 more comments

1 answer

0


First you have to check if really the value is a decimal, need to take the value of the text box and transform to the decimal, example:

decimal numero = 0;
if (decimal.TryParse(txtTelPesquisa.Text, out numero))
{
    var clientes = cc
          .TB_CLIENTEs
          .Where(c => c.TEL_CLIENTE == numero)
          .ToList();
}

If it passes it returns true and executes all that is within the if and the comparison with decimal must be done with equal.

References

Browser other questions tagged

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