SELECT RETORNA INCORRETO

KERPLUNK 28/06/2017 14:40:44
#474838
Afff...


public void logar()
{
if (cbNome.Text == string.Empty && txtSenha.Text == string.Empty)
{
///login ou senha estão em branco
}
using (FbConnection cn = new FbConnection([Ô]SUA CONNECTION STRING[Ô]))
{
cn.Open();
using (FbCommand cmd = new FbCommand([Ô]Select Count(0) from Login Where Login = @login and Senha = @senha[Ô], cn))
{
cmd.Parameters.AddWithValue([Ô]@login[Ô], cbNome.Text);
cmd.Parameters.AddWithValue([Ô]@senha[Ô], txtSenha.Text);
using (FbDataReader dr = cmd.ExecuteReader();
{
if (dr.GetInt32(dr.GetOrdinal(0)) == 0)
{
//login falhou, faça o que deve ser feito
}
else
{
//login ok
}
}
}
}
}


[Ô]Isso está em c#... teria como ser em VB.NET?[Ô]. Claro, basta usar um conversor de código.
SANROMAN 29/06/2017 10:48:30
#474870
Bom dia KERPLUNK

Desculpe nossa ignorância... Estamos aprendendo

Usei seu exemplo, tentei converter para vb.net, espero ter acertado.

Segue código:

 Private Function logando(usuario As String, senha As String) As Boolean

If cbNome.Text = String.Empty Or txtSenha.Text = String.Empty Then
MsgBox([Ô]Acesso não autorizado.[Ô] + vbCrLf _
+ [Ô]Login ou Senha estão vazios.[Ô], MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, [Ô]AI SOFT - LOGIN[Ô])
cbNome.Text = String.Empty
txtSenha.Text = String.Empty
txtNome.Text = String.Empty
cbNome.Focus()
Else
Try
Using con As FbConnection = conectarFirebird()
con.Open()

Using strCom As FbCommand = New FbCommand([Ô]Select COUNT(*) from tbLogin Where Login = @login and Senha = @senha[Ô], con)
strCom.Parameters.AddWithValue([Ô]@login[Ô], usuario)
strCom.Parameters.AddWithValue([Ô]@senha[Ô], senha)

Using dr As FbDataReader = strCom.ExecuteReader
If (dr.GetInt32(dr.GetOrdinal(0)) = 0) Then
MsgBox([Ô]Acesso não autorizado.[Ô] + vbCrLf _
+ [Ô]Os dados não conferem.[Ô], MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, [Ô]AI SOFT - LOGIN[Ô])
Else
Return True
End If
End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message).ToString()
End Try

End If
Return False
End Function


Dá o seguinte erro:
[Ô]Could not find especified collumn [ô]0[ô] in results.[Ô]

Se puder me ajudar, desde já agradeço.
KERPLUNK 29/06/2017 11:35:02
#474873
Aquele Getordinal(0) não precisa no lugar dele é só 0
SANROMAN 29/06/2017 11:57:09
#474876
Oi KERPLUNK

Dê uma olhada nisso:

 Try
Using con As SqlConnection = conectarDados()
con.Open()

Using strCom As SqlCommand = New SqlCommand([Ô]Select * from tbLogin Where Login = @login and Senha = @senha[Ô], con)
strCom.Parameters.AddWithValue([Ô]@login[Ô], usuario)
strCom.Parameters.AddWithValue([Ô]@senha[Ô], senha)

Using dr As SqlDataReader = strCom.ExecuteReader
[txt-color=#e80000] If Not (dr.HasRows)[/txt-color] Then
MsgBox([Ô]Acesso não autorizado.[Ô] + vbCrLf _
+ [Ô]Os dados não conferem.[Ô], MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, [Ô]AI SOFT - LOGIN[Ô])
Else
Return True
End If
End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message).ToString()
End Try


O código acima, com base em sql server, é exatamente igual ao código abaixo que usa a base de dados firebird.
Ele retorna FALSE se algum campo - login ou senha - não estiverem corretos.

 Try
Using con As fbConnection = conectarFirebird()
con.Open()

Using strCom As fbCommand = New fbCommand([Ô]Select * from tbLogin Where Login = @login and Senha = @senha[Ô], con)
strCom.Parameters.AddWithValue([Ô]@login[Ô], usuario)
strCom.Parameters.AddWithValue([Ô]@senha[Ô], senha)

Using dr As fbDataReader = strCom.ExecuteReader
[txt-color=#e80000]If Not (dr.HasRows)[/txt-color] Then
MsgBox([Ô]Acesso não autorizado.[Ô] + vbCrLf _
+ [Ô]Os dados não conferem.[Ô], MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, [Ô]AI SOFT - LOGIN[Ô])
Else
Return True
End If
End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message).ToString()
End Try


Esse é o código com base dados firebird sempre retorna TRUE não importando se os dados inseridos são Verdadeiros ou Falsos

Por que?

COQUITO 29/06/2017 12:41:42
#474877
Citação:

:
Oi KERPLUNK

Dê uma olhada nisso:

 Try
Using con As SqlConnection = conectarDados()
con.Open()

Using strCom As SqlCommand = New SqlCommand([Ô]Select * from tbLogin Where Login = @login and Senha = @senha[Ô], con)
strCom.Parameters.AddWithValue([Ô]@login[Ô], usuario)
strCom.Parameters.AddWithValue([Ô]@senha[Ô], senha)

Using dr As SqlDataReader = strCom.ExecuteReader
[txt-color=#e80000] If Not (dr.HasRows)[/txt-color] Then
MsgBox([Ô]Acesso não autorizado.[Ô] + vbCrLf _
+ [Ô]Os dados não conferem.[Ô], MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, [Ô]AI SOFT - LOGIN[Ô])
Else
Return True
End If
End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message).ToString()
End Try


O código acima, com base em sql server, é exatamente igual ao código abaixo que usa a base de dados firebird.
Ele retorna FALSE se algum campo - login ou senha - não estiverem corretos.

 Try
Using con As fbConnection = conectarFirebird()
con.Open()

Using strCom As fbCommand = New fbCommand([Ô]Select * from tbLogin Where Login = @login and Senha = @senha[Ô], con)
strCom.Parameters.AddWithValue([Ô]@login[Ô], usuario)
strCom.Parameters.AddWithValue([Ô]@senha[Ô], senha)

Using dr As fbDataReader = strCom.ExecuteReader
[txt-color=#e80000]If Not (dr.HasRows)[/txt-color] Then
MsgBox([Ô]Acesso não autorizado.[Ô] + vbCrLf _
+ [Ô]Os dados não conferem.[Ô], MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, [Ô]AI SOFT - LOGIN[Ô])
Else
Return True
End If
End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message).ToString()
End Try


Esse é o código com base dados firebird sempre retorna TRUE não importando se os dados inseridos são Verdadeiros ou Falsos

Por que?





cara vc se está enrolando no mesmo código e eu ainda nao recebi retorno do código que eu pedi testar. agora nesse novo lance

  
Using con As SqlConnection = conectarDados()
Try
con.Open()

dim dr As SqlDataReader = nothing
Using con As SqlConnection = conectarDados()
con.Open()
dim sql as tring=[Ô]SELECT * from tab_usuarios where Login_usuario=[ô][Ô] + Login_usuarioTextBox.Text + [Ô][ô] And Senha_usuario=[ô][Ô] + Senha_usuarioTextBox.Text + [Ô][ô][Ô]
dim cmd as new SqlCommand (sql,cn)
dr = cmd.ExecuteReader()

If Not (dr.HasRows) Then
MsgBox([Ô]Acesso não autorizado.[Ô] + vbCrLf _
+ [Ô]Os dados não conferem.[Ô], MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, [Ô]AI SOFT - LOGIN[Ô])
Else
[ô] Return True
MsgBox([Ô]Acesso autorizado.[Ô] , MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, [Ô]AI SOFT - LOGIN[Ô])
End If


Catch ex As Exception
MsgBox(ex.Message)
finally
cn.close
End Try
SANROMAN 29/06/2017 13:04:50
#474879
Olá COQUITO

O retorno foi dado.

Usei seu exemplo mas continua a retornar sempre TRUE.

Da uma olhada nos códigos que postei para o KERPLUNK baseados no exemplo que ele me deixou.

De sua opinião
COQUITO 29/06/2017 13:18:03
#474880
cara verifica de novo o código que respondi agora e da retorno, a ideia de KERPLUNK é dele vc está pedindo ajuda e vc tem que testar as nossa criatividade, se KERPLUNK mencionou algo posso somente acrescentar mas se nao houve pq eu entendi que exite outro meio.

SANROMAN 29/06/2017 15:11:53
#474881
Oi COQUITO

O problema não está em qual código usar, e sim em solucionar o porque de um mesmo trecho de código em SQL SERVER funcionar e em FIREBIRD não funcionar. Segue os códigos:

Em SQL SERVER - Funciona

 Private Function logando(usuario As String, senha As String) As Boolean

If cbNome.Text = String.Empty Or txtSenha.Text = String.Empty Then
MsgBox([Ô]Acesso não autorizado.[Ô] + vbCrLf _
+ [Ô]Login ou Senha estão vazios.[Ô], MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, [Ô]AI SOFT - LOGIN[Ô])
cbNome.Text = String.Empty
txtSenha.Text = String.Empty
txtNome.Text = String.Empty
cbNome.Focus()
Else
Try
Using con As SqlConnection = conectarDados()
con.Open()

Using strCom As SqlCommand = New SqlCommand([Ô]Select * from tbLogin Where Login = @login and Senha = @senha[Ô], con)
strCom.Parameters.AddWithValue([Ô]@login[Ô], usuario)
strCom.Parameters.AddWithValue([Ô]@senha[Ô], senha)

Using dr As SqlDataReader = strCom.ExecuteReader
[txt-color=#0000f0] If Not (dr.HasRows) Then [ô] Se a senha ou login estiverem corretos retorna TRUE se não retorna FALSE - Correto[/txt-color]
MsgBox([Ô]Acesso não autorizado.[Ô] + vbCrLf _
+ [Ô]Os dados não conferem.[Ô], MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, [Ô]AI SOFT - LOGIN[Ô])
Else
Return True
End If
End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message).ToString()
End Try
End If
Return False
End Function



Em FIREBIRD - Não funciona

  If cbNome.Text = String.Empty Or txtSenha.Text = String.Empty Then
MsgBox([Ô]Acesso não autorizado.[Ô] + vbCrLf _
+ [Ô]Login ou Senha estão vazios.[Ô], MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, [Ô]AI SOFT - LOGIN[Ô])
cbNome.Text = String.Empty
txtSenha.Text = String.Empty
txtNome.Text = String.Empty
cbNome.Focus()
Else
Try
Using con As FbConnection = conectarFirebird()
con.Open()

Using strCom As FbCommand = New FbCommand([Ô]Select * from tbLogin Where Login = @login and Senha = @senha[Ô], con)
strCom.Parameters.AddWithValue([Ô]@login[Ô], usuario)
strCom.Parameters.AddWithValue([Ô]@senha[Ô], senha)

Using dr As FbDataReader = strCom.ExecuteReader()
[txt-color=#e80000] If (dr.HasRows) Then [ô] Sempre retorna TRUE mesmo se a senha ou login estiverem incorretos. - Errado[/txt-color]
Return True
Else
MsgBox([Ô]Acesso não autorizado.[Ô] + vbCrLf _
+ [Ô]Os dados não conferem.[Ô], MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, [Ô]AI SOFT - LOGIN[Ô])
End If
End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message).ToString()
End Try
End If
Return False
End Function


Gostaria muito da ajuda de todos.

KERPLUNK 29/06/2017 16:25:02
#474883
No caso do Firebird, verifique o que está sendo retornado. Se o HasRows está true, é que tem linha(s)
SANROMAN 29/06/2017 17:55:57
#474891
Boa Noite KERPLUNK

Segui seu exemplo, olhei com mais calma e fiz as seguintes mudanças - em vermelho - como informado por vc.

Está funcionando bem.

Segue o código final:
 Try
Using con As FbConnection = conectarFirebird()
con.Open()

Using strCom As FbCommand = New FbCommand([Ô]SELECT COUNT(*) FROM tbLogin [Ô] & _
[Ô]WHERE Login = @login [Ô] & _
[Ô]AND Senha = @senha[Ô], con)

strCom.Parameters.AddWithValue([Ô]@login[Ô], usuario)
strCom.Parameters.AddWithValue([Ô]@senha[Ô], senha)

Using dr As FbDataReader = strCom.ExecuteReader()
[txt-color=#0000f0]dr.Read() [ô] Não estava digitado

[/txt-color]If dr.GetInt32(0) Then [ô] Estava if dr.hasrows then
Return True
Else
MsgBox([Ô]Acesso não autorizado.[Ô] + vbCrLf _
+ [Ô]Os dados não conferem.[Ô], MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, [Ô]AI SOFT - LOGIN[Ô])
End If
End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message).ToString()
End Try


Muito obrigado a todos.
Estou encerrando o tópico


Página 2 de 2 [20 registro(s)]
Tópico encerrado , respostas não são mais permitidas