3
I have this method where I would like to bring the IBGE. When I put Textbox as a parameter, it usually brings it, but the problem is that I am using a Library and cannot import Textbox. So I replaced Textbox with a string, but that way it can’t bring... Someone can help me?
public bool recuperarIBGE(string Cidade, string IBGE)
{
conexao = new Conexao();
try
{
conexao.conectar();
conexao.abrirConexao();
NpgsqlCommand sql = new NpgsqlCommand("SELECT codibge FROM cidade WHERE nome ilike SEM_ACENTO('" + Cidade + "');", conexao.conexao);
NpgsqlDataReader dr = sql.ExecuteReader();
while (dr.Read())
{
//IBGE.Text = (string)dr["codibge"].ToString();
IBGE = (string)dr["codibge"].ToString();
retorno = true;
}
conexao.fecharConexao();
}
catch (Exception erro)
{
throw erro;
}
return retorno;
}
where is your error? is in your query?
– Marconi
Actually there is no error, the only doubt is that it cannot return anything when the parameter is a string. Already when it is a Textbox, it returns normally... Some solution to this or I did something wrong?
– Emerson
I understood it is because I saw an ilike in your query and I just found out that you use the postgre bank. Try to put %SEM_ACENTO('" + City + "');%. Note that add the %
– Marconi
@Marconi, so did not... It would have to be done this way then: SEM_ACENTO('%" + City + "%');. I tested direct on Postgres and so it returns me several city codes =/
– Emerson
Got it, weird that more if it worked out all right.
– Marconi
But I can’t let him bring any. I put Jaú as an example in the city and he returned me several cities that have Jaú in the middle...
– Emerson
Let’s go continue this discussion in chat.
– Marconi
Join the chat there.
– Marconi
I entered, but I can’t send
– Emerson