ludgero1993 Posted May 9, 2013 at 02:04 PM Report #506417 Posted May 9, 2013 at 02:04 PM "SELECT * from Pessoa" & _ " WHERE Nome_da_Empresa LIKE '%" & TextBox5.Text & "%'" & _ " OR Nome_da_pessoa LIKE '%" & TextBox2.Text & "%'" & _ " OR Nº_telemovel LIKE '%" & TextBox3.Text & "%'" & _ " OR nome_do_cargo LIKE '%" & TextBox4.Text & "%'" esta query esta bem ?
nelsonr Posted May 9, 2013 at 02:12 PM Report #506421 Posted May 9, 2013 at 02:12 PM (edited) Isso é para que base de dados? MSSQL? Assim à primeira vista parece bem, mas mudava o campo do nº_telemovel para não incluir o caracter º e tinha de fazer ai um filtro para não deixar incluir o caracter ' nos textos (para diminuir o risco de SQL Injection) -- EDIT -- No entanto, poderás ter ai um problema se algum dos campos for vazio, ficando campo like '%%', retornando todos os registos Edited May 9, 2013 at 02:15 PM by nelsonr
ludgero1993 Posted May 9, 2013 at 02:17 PM Author Report #506423 Posted May 9, 2013 at 02:17 PM exacto e isso que eu quero que para filtrar mas ele aparece tudo branco ja tentei tudo ja nao sei o que fazer se for so um campo ele faz a pesquisa direitinha agora se for varios ja nao da
nelsonr Posted May 9, 2013 at 02:33 PM Report #506428 Posted May 9, 2013 at 02:33 PM (edited) Crias uma string e vais adicionando o filtro caso o campo tenha texto. Algo do tipo: dim sql as string sql="" ' Remover as plicas TextBox5.Text=TextBox5.Text.Replace("'","") TextBox2.Text=TextBox2.Text.Replace("'","") ' Nome da empresa If Not String.IsNullOrEmpty(TextBox5.Text) then sql="Nome_da_Empresa LIKE '%" & TextBox5.Text & "%'" end if ' Nome da pessoa If Not String.IsNullOrEmpty(TextBox2.Text) then if not String.IsNullOrEmpty(sql) then sql=sql+" OR " endif sql=sql + "Nome_da_pessoa LIKE '%" & TextBox2.Text & "%'" end if ' ... adicionar aqui os outros campos ' if not String.IsNullOrEmpty(sql) then sql="SELECT * from Pessoa WHERE "+sql else sql="SELECT * from Pessoa" endif Atenção que não tenho o VB instalado, não sei se compila, mas é para ficares com uma idea -- EDIT -- Já agora, se o objectivo é que o conteúdo tem de estar de acordo com todos os filtros definidos, tens de mudar o OR para AND Edited May 9, 2013 at 02:44 PM by nelsonr
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now