[RESOLVED] problema with sql query
Hi,
I'm with a little problem, here is the code:
[VB] Code:
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class LoginForm1
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim ConexaoBD As OleDbConnection
Dim DsDados As DataSet
Dim sqlStringUser As String = "SELECT * FROM user WHERE USERNAME='" & tbUsername.Text & "' and PASSWORD='" _
& tbPassword.Text & "'"
ConexaoBD = New OleDbConnection(connstring)
Dim AdaptadorDadosUser As OleDbDataAdapter = New OleDbDataAdapter(sqlStringUser, ConexaoBD)
DsDados = New DataSet()
AdaptadorDadosUser.Fill(DsDados, "user")
If DsDados.Tables("user").Rows.Count() = 0 Then
MsgBox("Username ou Password Errada", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ERRO")
tbUsername.Text = ""
tbPassword.Text = ""
tbUsername.Focus()
Else
frmmdi.Show()
Me.Close()
End If
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
End Class
the problem is when I try to login, there a bug says there is a error sintax in the "from"
Re: problema with sql query
Welcome to VBForums :wave:
The problem is that Username and/or Password are reserved words, and as such should not be used as a field/table name (it confuses the query parser within the database system).
If you change the field names (in the database and your code), it should work correctly.
For more information, see the article What names should I NOT use for tables/fields/views/stored procedures/...? from our Database Development FAQs/Tutorials (at the top of the Database Development forum)
Re: problema with sql query
By the way, I use other names is "nome" and "pass"
Re: problema with sql query
Quote:
The problem is that Username and/or Password are reserved words, and as such should not be used as a field/table name
si_the_geek meant the filed names should be other than "username" and "password"
Quote:
By the way, I use other names is "nome" and "pass"
but not the values of the fields
Re: problema with sql query
yes I understand, and the name of the field are nome and pass, the error still there.
Re: problema with sql query
Great,
I resolve by changing the table name to "utilizadores", it was "user"
Thanks
Re: problema with sql query
ohhh k
well i am not sure but the table name 'user' may be the culprit
edit:
well must have refreshed before posting