3
Good morning
I would like to ask a question about a dynamic research.
Setting:
I have a search screen, where the user selects 3 fields, being them:
- The first is the search screen field, where you select which field you want to fetch the value.
- The second will be the condition where you can select the values = Containing, Starting, Ending or Equal
- The Third would be the value he wishes to research
So what would be the best way to develop this in C#?
- Create dropdown with the values of the fields and conditions. Then create a method where I take the informed values and so generate a switch case with the conditions data? more or less like this:
->
public Cliente pesquisarCliente(string condicao, string campo, string valor)
{
string operador = "";
string sql;
switch(condicao)
{
case "Condendo":
operador = "LIKE %"+ valor +"%";
break;
case "Iniciando":
operador = "LIKE %"+ valor;
break;
case "Terminando":
operador = "LIKE "+ valor +"%";
break;
case "Igual":
operador = " = "+ valor;
break;
}
sql = "SELECT * FROM CLIENTES where @campo "+valor;
Com = new NpgsqlCommand (sql);
}
That would be the best way ? Someone would have another way to develop it?
I don’t know if I was clear in my doubt.
Thank you for your attention.
OBS: I am developing in c# layers with WPF and Postgresql database; I own the layers DAL, BLL, GUI and Model
Escape like use full text search there are implementations for all banks.
– Marco Vinicius Soares Dalalba