← Desenvolvimento

ERRO POR FAVOR ALGUEM ME AJUDE

Lida 1584 vezes

Offline

cmtavares 
Membro
Mensagens 5 Gostos 0
Troféus totais: 12
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 2 Level 1 First Post Karma Fifth year Anniversary Fourth year Anniversary Third year Anniversary

Boa tarde pessoal, gostaria de saber qual o motivo para este codigo estar a dar erro! este codigo está a ser desenvolvido para efetuar o login de utilizadores de uma empresa.

A liguagem e VB

a linha em que me está a dar o erro é:

Código: [Seleccione]
cmd.CommandText = "select count (*) from Utilizador where Nome = '" & txtUser.Text & "' AND Password = '" & txtPass.Text & "';"
Código: [Seleccione]
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        Dim connectionString As String = "Password=irpasimpo;Persist Security Info=True;User ID=SA;Initial Catalog=OEI;Data Source=CARLOS-M\SQL"
        Dim connection As New SqlConnection(connectionString)
        Dim cmd As SqlClient.SqlCommand
        connection.Open()

        cmd.CommandText = "select count (*) from Utilizador where Nome = '" & txtUser.Text & "' AND Password = '" & txtPass.Text & "';"
        cmd.Connection = connection
        Dim rowValue As String = cmd.ExecuteScalar

        If rowValue = "0" Then

            MessageBox.Show("Invalid Login information.", "Ooops!", MessageBoxButtons.OK, MessageBoxIcon.Stop)

            txtUser.Focus()

        Else
            MessageBox.Show("Login success!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information)

        End If

        connection.Close()


    End Sub

Agradecia toda a ajuda possivel!
Offline

slack 
Membro
Mensagens 116 Gostos 0
Feedback +4

Troféus totais: 21
Trófeus: (Ver todos)
Windows User Super Combination Combination Topic Starter Level 4 Level 3 Level 2 Level 1 100 Posts 50 Posts

Boas cmtavares,

O meu VB ja anda enferrujado mas vou tentar ajudar.

1- Não sei se usas case-sensitive se usas, fay o update de select=SELECT, from=FROM, where=WHERE
2- No teu sqlClient.SqlCommand. Altera para:
Dim cmd As System.Data.SqlClient.SqlCommand

3- Tenta:

cmd.CommandText = "SELECT COUNT(*) FROM Utilizador WHERE (Nome = '" & txtUser.Text & "') AND (Password = '" & txtPass.Text & "')"


Abracos
Offline

jof 
Membro
Mensagens 1117 Gostos 35
Feedback +45

Troféus totais: 34
Trófeus: (Ver todos)
Avatar Signature Tenth year Anniversary Level 6 Quick Poster Linux User Mobile User Windows User Super Combination Combination

experimenta usar (), tipo where (Nome = '')
e no final penso que está lá um erro será "; em vez de ;"
Offline

zegomes 
Membro
Mensagens 724 Gostos 0
Feedback +9

Troféus totais: 21
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 4 Level 3 Level 2 Level 1 500 Posts 100 Posts

Antes demais, posta aí que erro é que está a dar  :)
Offline

cmtavares 
Membro
Mensagens 5 Gostos 0
Troféus totais: 12
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 2 Level 1 First Post Karma Fifth year Anniversary Fourth year Anniversary Third year Anniversary

Pessoal obrigada na mesma, mas já consegui arranjar uma solução!

ABRAÇOS :D

 :obrigado: