none
Pesquisa por dois campos no banco RRS feed

  • Pergunta


  • Gente estou fazendo uma aplicação e estou tentando resolver o seguinte programa:

    Tenho um campo de pesquisa chamado textboxCEP_D.text e tenho  dois campos no meu banco, chamados CEP_D e CEP_E

    Eu gostaria saber se é possivel usar os numeros digitados no textboxCEP_D.text, para pesquisar tanto no campo CEP_D quanto no campo CEP_E

    Segue meu código..

    Public Class frmPesquisa
        Private Sub carregargrid()
            strsql = "SELECT * FROM Lograd_MSE_Nov2014 ORDER BY Denominação"
            Dim objCommand As New OleDbCommand(strsql, conn)
            dr_Lograd_MSE_Nov2014 = objCommand.ExecuteReader()
            bs_Lograd_MSE_Nov2014.DataSource = dr_Lograd_MSE_Nov2014
            DataGridView1.DataSource = bs_Lograd_MSE_Nov2014


            DataGridView1.Columns(0).HeaderCell.Value = "ID"
            DataGridView1.Columns(1).HeaderCell.Value = "Denominação"
            DataGridView1.Columns(2).HeaderCell.Value = "CEP Direto"
            DataGridView1.Columns(3).HeaderCell.Value = "CEP Esquerdo"
            DataGridView1.Columns(4).HeaderCell.Value = "Número Incial Esquerdo"
            DataGridView1.Columns(5).HeaderCell.Value = "Número Final Esquerdo"
            DataGridView1.Columns(6).HeaderCell.Value = "Número Inicial Direito"
            DataGridView1.Columns(7).HeaderCell.Value = "Número Final Direito"
            DataGridView1.Columns(9).HeaderCell.Value = "Bairro"
            DataGridView1.Columns(12).HeaderCell.Value = "CEP MSE"


        End Sub
        Private Sub limpar()
            TextBoxCEP.Clear()
            TextBoxRua.Clear()
            'TextBoxNumero.Clear()
            TextBoxBairro.Clear()
            TextBoxDistrito.Clear()
        End Sub
        Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            conn.Open()
            carregargrid()

        End Sub

        Private Sub TextBoxRua_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxRua.TextChanged

            strsql = "SELECT * FROM Lograd_MSE_Nov2014 where Denominação like '" + TextBoxRua.Text + "%' AND Distrito like'" + TextBoxDistrito.Text + "%' AND CEP_D like'" + TextBoxCEP.Text + "%' AND BAIRRO_D like '" + TextBoxBairro.Text + "%' ORDER BY Denominação"


            Dim objCommnad As New OleDbCommand(strsql, conn)
            dr_Lograd_MSE_Nov2014 = objCommnad.ExecuteReader
            bs_Lograd_MSE_Nov2014.DataSource = dr_Lograd_MSE_Nov2014



        End Sub

        Private Sub TextBoxDistrito_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxDistrito.TextChanged
            strsql = "SELECT * FROM Lograd_MSE_Nov2014 where Denominação like '" + TextBoxRua.Text + "%' AND Distrito like'" + TextBoxDistrito.Text + "%' AND CEP_D like'" + TextBoxCEP.Text + "%' AND BAIRRO_D like '" + TextBoxBairro.Text + "%' ORDER BY Denominação"


            Dim objCommnad As New OleDbCommand(strsql, conn)
            dr_Lograd_MSE_Nov2014 = objCommnad.ExecuteReader
            bs_Lograd_MSE_Nov2014.DataSource = dr_Lograd_MSE_Nov2014


        End Sub

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            frmResultadoPesquisa.ShowDialog()
        End Sub

        Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        End Sub

        Private Sub frmPesquisa_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
            If MsgBox("Deseja realmente sair?? ", MsgBoxStyle.YesNo, "Encerrando.......") = MsgBoxResult.No Then
                e.Cancel = True
            Else
                conn.Close()
            End If
        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            limpar()
        End Sub

        Private Sub TextBoxCEP_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxCEP.TextChanged
           strsql = "SELECT * FROM Lograd_MSE_Nov2014 where Denominação like '" + TextBoxRua.Text + "%' AND Distrito like'" + TextBoxDistrito.Text + "%' AND CEP_D like'" + TextBoxCEP.Text + "%' AND BAIRRO_D like '" + TextBoxBairro.Text + "%' ORDER BY Denominação"

            Dim objCommnad As New OleDbCommand(strsql, conn)
            dr_Lograd_MSE_Nov2014 = objCommnad.ExecuteReader
            bs_Lograd_MSE_Nov2014.DataSource = dr_Lograd_MSE_Nov2014

        End Sub

        Private Sub TextBoxNumero_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)



        End Sub

        Private Sub TextBoxBairro_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxBairro.TextChanged
          strsql = "SELECT * FROM Lograd_MSE_Nov2014 where Denominação like '" + TextBoxRua.Text + "%' AND Distrito like'" + TextBoxDistrito.Text + "%' AND CEP_D like'" + TextBoxCEP.Text + "%' AND BAIRRO_D like '" + TextBoxBairro.Text + "%' ORDER BY Denominação"
            Dim objCommnad As New OleDbCommand(strsql, conn)
            dr_Lograd_MSE_Nov2014 = objCommnad.ExecuteReader
            bs_Lograd_MSE_Nov2014.DataSource = dr_Lograd_MSE_Nov2014

        End Sub

        Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

        End Sub

        Private Sub DataGridView1_SortCompare(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewSortCompareEventArgs) Handles DataGridView1.SortCompare

        End Sub

        Private Sub Label2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)

        End Sub
    End Class

    sexta-feira, 19 de dezembro de 2014 15:38

Todas as Respostas

  • Bom dia Geovani,

    Você quer saber se funciona apenas, ou você ja testou alguma coisa e não funcionou?

    Att,


    Ricardo Cortes Microsoft Contingent Staff

    Esse contedo e fornecido sem garantias de qualquer tipo, seja expressa ou implicita.

    MSDN Community Support

    segunda-feira, 22 de dezembro de 2014 11:09