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  
debliu

Dúvida sobre SELECT em Access

Recommended Posts

Asgorath

Boas.

Usas o ExecuteReader()


"The Dark Side Clouds Everthing. Impossible To See The Future Is."My rig: Intel Core 2 Quad Q9450 | abit IP35P | 4G Kingston 800 Mhz | XFX GeForce 9800 GX2 1G ddr3 | 2X WD5000AAJS 500Gb Sata 2 | PSU 600W || Caixa El-Diablo | Creative XMod

Share this post


Link to post
Share on other sites
Hellblazer

Por acaso não conheço muito bem acess mas nao terá o Access algo tipo o rownum? seria mais interessante seleccionares tipo o rownum 2 e depois um executescalar :) vou investigar :)


There are two ways to write error-free programs; only the third one works.

Share this post


Link to post
Share on other sites
Hellblazer

Não econtrei melhor tipo de solução :S ve se este codigo funciona :) meti a função a retornar um objecto porque nao sei que tipo de dados queres apanhar.

Imports System.Data.OleDb

Public Function GetSecondValue(ByVal strSQL As String, ByVal strConnectionString As String) As Object

        Dim myConnection As OleDbConnection
        Dim myCommand As OleDbCommand
        Dim dr As OleDbDataReader
        Dim i As Integer = 0
        Dim ObjectReturn As Object
        myConnection = New OleDbConnection(strConnectionString)
        Try
            myConnection.Open()
            If myConnection.State = ConnectionState.Open Then
                myCommand = New OleDbCommand(strSQL, myConnection)
                dr = myCommand.ExecuteReader()
                While dr.Read()
                    If i = 1 Then
                        ObjectReturn = dr(0)
                    End If
                    i += 1
                End While
                dr.Close()
                myConnection.Close()
            Else
                MessageBox.Show("Não se conectou.", "Aviso")
            End If



        Catch e As Exception

        End Try

        Return ObjectReturn

    End Function


There are two ways to write error-free programs; only the third one works.

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.