Jump to content

Recommended Posts

Posted

Olá, preciso fazer um login para o meu projecto final de curso e está a dar-me um erro na conexão à base de dados access.

O erro está nesta parte do código: command.connection.open()

O erro diz: nullreferenceexception was unhandled.

CÓDIGO:

Dim connection As New OleDbConnection

Dim command As New OleDbCommand

provedor = "provider=Microsoft.ACE.OLEDB.12.0;"

fonte = "Data Source = C:\Users\ruben_000\Desktop\Lallemand - Fornecedores\Fornecedores.accdb"

Dim usernameParam As New OleDbParameter("username", Me.txt_user.Text)

Dim passwordParam As New OleDbParameter("password", Me.txt_password.Text)

command.Parameters.Add(usernameParam)

command.Parameters.Add(passwordParam)

command.Connection.Open()

Dim reader As OleDbDataReader = command.ExecuteReader()

If reader.HasRows Then

MessageBox.Show("Bem-Vindo!")

MyPlayer.SoundLocation = path & LogOnsound

MyPlayer.Play()

txt_password.Text = ""

Me.Hide()

frm_menu.Show()

Else

MessageBox.Show("O nome de Utilizador ou Password estão incorretos!")

txt_password.Text = ""

End If

command.Connection.Close()

Não sou bom programador, se alguém me poder ajudar, ficaria muito agradecido!

Posted

Sempre que colocares código, coloca-o entre tags: [ code = linguagem ][ /code ] (sem os espaços). Portanto, como estás a questionar sobre VB.NET, utilizas: [ code = vbnet ][ /code ].

Por fim, a resposta ao teu problema é simples.

command.Connection.Open()

O que tu queres é antes:

Connection.Open();

No entanto é necessário que atribuas a connectionstring à connection.

Para além do link que já te dei https://wiki.portugal-a-programar.pt/dev_net/vb.net/poptextbox/

O código está aí chapado, portanto olha com olhos de ver.

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.