SELECT RETORNA INCORRETO
Afff...
[Ô]Isso está em c#... teria como ser em VB.NET?[Ô]. Claro, basta usar um conversor de código.
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.
Bom dia KERPLUNK
Desculpe nossa ignorância... Estamos aprendendo
Usei seu exemplo, tentei converter para vb.net, espero ter acertado.
Segue código:
Dá o seguinte erro:
[Ô]Could not find especified collumn [ô]0[ô] in results.[Ô]
Se puder me ajudar, desde já agradeço.
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.
Aquele Getordinal(0) não precisa no lugar dele é só 0
Oi KERPLUNK
Dê uma olhada nisso:
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.
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?
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?
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
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
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
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.
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
Em FIREBIRD - Não funciona
Gostaria muito da ajuda de todos.
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.
No caso do Firebird, verifique o que está sendo retornado. Se o HasRows está true, é que tem linha(s)
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:
Muito obrigado a todos.
Estou encerrando o tópico
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
Tópico encerrado , respostas não são mais permitidas