Results 1 to 7 of 7

Thread: [RESOLVED] problema with sql query

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    18

    Resolved [RESOLVED] problema with sql query

    Hi,

    I'm with a little problem, here is the code:
    [VB] Code:
    1. Imports System
    2. Imports System.Data
    3. Imports System.Data.OleDb
    4.  
    5.  
    6. Public Class LoginForm1
    7.     Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
    8.         Dim ConexaoBD As OleDbConnection
    9.         Dim DsDados As DataSet
    10.  
    11.         Dim sqlStringUser As String = "SELECT * FROM user WHERE USERNAME='" & tbUsername.Text & "' and PASSWORD='" _
    12.                                     & tbPassword.Text & "'"
    13.         ConexaoBD = New OleDbConnection(connstring)
    14.  
    15.         Dim AdaptadorDadosUser As OleDbDataAdapter = New OleDbDataAdapter(sqlStringUser, ConexaoBD)
    16.         DsDados = New DataSet()
    17.  
    18.         AdaptadorDadosUser.Fill(DsDados, "user")
    19.  
    20.         If DsDados.Tables("user").Rows.Count() = 0 Then
    21.             MsgBox("Username ou Password Errada", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ERRO")
    22.             tbUsername.Text = ""
    23.             tbPassword.Text = ""
    24.             tbUsername.Focus()
    25.         Else
    26.             frmmdi.Show()
    27.             Me.Close()
    28.         End If
    29.  
    30.     End Sub
    31.  
    32.     Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
    33.         Me.Close()
    34.     End Sub
    35. End Class

    the problem is when I try to login, there a bug says there is a error sintax in the "from"

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: problema with sql query

    Welcome to VBForums

    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)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    18

    Re: problema with sql query

    By the way, I use other names is "nome" and "pass"

  4. #4
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: problema with sql query

    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"

    By the way, I use other names is "nome" and "pass"
    but not the values of the fields

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    18

    Re: problema with sql query

    yes I understand, and the name of the field are nome and pass, the error still there.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    18

    Re: problema with sql query

    Great,

    I resolve by changing the table name to "utilizadores", it was "user"


    Thanks

  7. #7
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width