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

Mica

Erro ao ligar à base de dados

Recommended Posts

Mica


....

Dim connection As New OleDbConnection(myconnectionString)
        Dim datareader As OleDbDataReader
        Dim command As New OleDbCommand("Select id from produtos where id=2  , connection)")

        connection.Open()
        datareader = command.ExecuteReader

        While datareader.Read
            'lê os dados

            ListBox1.Text = (datareader.Item("preço"))

        End While

        datareader.Close()
        connection.Close()
        connection = Nothing
        Command = Nothing[b][/b]
...

Bem o seguinte erro passasse nesta linha de código "datareader = command.ExecuteReader"

ExecuteReader: Connection property has not been initialized.

Quem puder ajudar na sua resolução agradeço :)

Share this post


Link to post
Share on other sites
ribeiro55
Dim command As New OleDbCommand("Select id from produtos where id=2"  , connection)


Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Share this post


Link to post
Share on other sites
PedroWieira

Dim datareader As OleDbDataReader

Tem de ter um construtor, ou seja:

Dim datareader As New OleDbDataReader

Cumps!

Share this post


Link to post
Share on other sites
duduml

Dim datareader As OleDbDataReader

Tem de ter um construtor, ou seja:

Dim datareader As New OleDbDataReader

Cumps!

?? tens a certeza do que  estas a escrever??? não me parece que seja verdade...aliás, discordo completamente!

O único erro será o que o Ribeiro55 referiu...

CUMPS


"use windows, você merece!"

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

×

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.