Jump to content

Recommended Posts

Posted

fiz algo tipo isto...

DataGridView1.Columns.Clear()

                Const constr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\axpp\Ambiente de trabalho\controloantidoping\aplicaçãoantidopping\aplicaçãoantidopping\controlo_antidoping.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

        Dim db As New SqlConnection(constr)

        db.Open()
        Dim varsql As String
        Dim num_campos As Integer
        Dim campo As String

        varsql = "select * from controlo_antidoping where Nome like '%' + @esquisa2 + '%'"
        Dim cmd As New SqlCommand(varsql, db)
        cmd.parameters.add("@pesquisa2", SqlDbType.VarChar).Value = pesquisa1.text
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader
        num_campos = dr.FieldCount

        Dim idx_linha As Integer = 0
        Dim idx As Integer

        For idx = 0 To num_campos - 1
            campo = dr.GetName(idx)
            DataGridView1.Columns.Add(campo, campo)
        Next

        While dr.Read
            Dim linha As New DataGridViewRow()
            DataGridView1.Rows.Add(linha)
            DataGridView1.Rows(idx_linha).Cells(0).Value = dr.Item(0)
            DataGridView1.Rows(idx_linha).Cells(1).Value = RTrim(dr.Item(1))


            DataGridView1.Rows(idx_linha).Cells(2).Value = dr.Item(2)
            DataGridView1.Rows(idx_linha).Cells(3).Value = Trim(dr.Item(3))
            DataGridView1.Rows(idx_linha).Cells(4).Value = Trim(dr.Item(4))
            DataGridView1.Rows(idx_linha).Cells(5).Value = Trim(dr.Item(5))
            DataGridView1.Rows(idx_linha).Cells(6).Value = Trim(dr.Item(6))
            DataGridView1.Rows(idx_linha).Cells(7).Value = Trim(dr.Item(7))

            DataGridView1.Rows(idx_linha).Cells(8).Value = Trim(dr.Item(8))
            DataGridView1.Rows(idx_linha).Cells(9).Value = Trim(dr.Item(9))
            DataGridView1.Rows(idx_linha).Cells(10).Value = Trim(dr.Item(10))
            DataGridView1.Rows(idx_linha).Cells(11).Value = Trim(dr.Item(11))
            DataGridView1.Rows(idx_linha).Cells(12).Value = Trim(dr.Item(12))


            idx_linha = idx_linha + 1

        End While

        DataGridView1.AutoResizeColumnHeadersHeight()
        DataGridView1.AutoResizeColumns()
        DataGridView1.AutoResizeRows()

        dr.Close()
        db.Close()

o pesquisa 1 é uma textbox onde eu insiro o nome que quero procurar.

problema resolvido =D

obrigado a todos pela ajuda :cheers:

Posted

ja agora sera que alguem sabe como fazer a mesma pesquisa mas para uma data??

usando na mesma parametros para o dia, mes e ano é que eu ja tive a tentar com # @dia - @mes - @ano # e da me erro

Posted

Se queres passar uma data, a melhor forma é usares um parâmetro como fizeste no caso do nome.

"Give a man a fish and he will eat for a day; Teach a man to fish and he will eat for a lifetime. The moral? READ THE MANUAL !"

Sign on a computer system consultant's desk

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.