Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
Luis Marques

Pesquisa atravez da data

Recommended Posts

Luis Marques

Boas,

Estou a fazer uma pesquisa através da data, não está a dar erro nem nada, mas nao me preenche os campos da datagridview, aparece em branco.

Estou a usar este codigo:

        Dim db As New OleDbConnection(pap.My.Settings.ligacaoBD)

        ' LIGAR A BD

        db.Open()

        ' ACESSO AOS DADOS

        Dim comandosql = "Select id_encomenda, id_cliente, data,descricao,responsavel_pd,total from encomenda where data = " + DataDateTimePicker.Value

        Dim cmd As New OleDbCommand(comandosql, db)

        Dim dtr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

        ' CRIAÇÃO DE COLUNAS NO DATAGRIDVIEW

        Dim num_campos As Integer

        Dim campo As String

        DataGridView1.Columns.Clear()

        num_campos = dtr.FieldCount

        For idx = 0 To num_campos - 1

            campo = dtr.GetName(idx)

            DataGridView1.Columns.Add(campo, campo)

        Next

        ' CARREGAR OS DADOS

        Dim idx_linha As Integer

        idx_linha = 0

        While dtr.Read()

            Dim linha As New DataGridViewRow()

            DataGridView1.Rows.Add(linha)

            DataGridView1.Rows(idx_linha).Cells(0).Value = dtr.Item(0)

            DataGridView1.Rows(idx_linha).Cells(1).Value = RTrim(dtr.Item(1))

            DataGridView1.Rows(idx_linha).Cells(2).Value = RTrim(dtr.Item(2))

            DataGridView1.Rows(idx_linha).Cells(3).Value = RTrim(dtr.Item(3))

            DataGridView1.Rows(idx_linha).Cells(4).Value = RTrim(dtr.Item(4))

            DataGridView1.Rows(idx_linha).Cells(5).Value = RTrim(dtr.Item(5))

            idx_linha = idx_linha + 1

        End While

        ' AJUSTE DAS COLUNAS DO DATAGRIDVIEW

        DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells

        ' FECHAR A BD

        dtr.Close()


LM

Share this post


Link to post
Share on other sites
esquima

faz o teste so com este codigo  --ignora o teu

Dim db As New OleDbConnection(pap.My.Settings.ligacaoBD)

Dim comandosql = "Select id_encomenda, id_cliente, data,descricao,responsavel_pd,total from encomenda where data = " + DataDateTimePicker.Value

  ' LIGAR A BD

  db.Open()

Dim sqlDa as New SqlDataAdapter(comandosql , db )

Dim dt as new DataTable

sqlDa.Fill(dt)

DataGridView1.DataSourse = dt

db.Close()

Share this post


Link to post
Share on other sites
José Lopes

o problema nao e esse... no access a pesquisa por data tem que ser:  #data aqui no meio#

mas pergunta ao google sobre pesquisa sobre datas em access


Quando te pedirem peixe.... ensina-os a Pescar!!Hum..lálálálá!!

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

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.