CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2001
    Posts
    29

    Syntax Error in Recordset

    There are four core objects in the form - txtUserName, txtPassword, cmdOK and cmdCancel. A database named LoginY2K.mdb is connected to this form. It contains a table named User which comprising UserName and Pasword two fields. Below is the coding:

    option Explicit
    public LoginSucceeded as Boolean
    ---------------------------------------------------------------
    private Sub cmdCancel_Click()
    'set the global var to false
    'to denote a failed login
    LoginSucceeded = false
    End
    End Sub
    ---------------------------------------------------------------
    private Sub cmdOK_Click()
    Dim conAdo as ADODB.Connection
    Dim rstAdo as ADODB.Recordset

    set conAdo = new ADODB.Connection
    set rstAdo = new ADODB.Recordset
    conAdo.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Login Security\LoginY2K.mdb;Persist Security Info=false"
    rstAdo.Open "Select * From User Where UserName = '" & txtUserName.Text & "';", conAdo, adOpenStatic, adLockOptimistic, adCmdText 'error OCCURS HERE !!!

    MsgBox rstAdo.RecordCount & "found." 'Just to test
    'check for correct password
    If txtPassword .txt= rstAdo.Fields("Password") then
    'place code to here to pass the
    'success to the calling sub
    'setting a global var is the easiest
    LoginSucceeded = true
    MsgBox "U r here" ' Just to test
    else
    MsgBox "Invalid Password, try again!", , "Login"
    txtPassword.SetFocus
    SendKeys "{Home}+{End}"
    End If
    End Sub



    But an error pops up saying," Run-time error '-2147217900 (8004e14); Syntax error in FROM clause. " after submitting the user name and password. (pls look at ERROR OCCURS HERE)

    Can anyone help me???



  2. #2
    Join Date
    Jul 2001
    Location
    maharashtra,india
    Posts
    181

    Re: Syntax Error in Recordset

    instead of cmdtext
    try adcmdtable
    i think this might work
    best of luck


  3. #3
    Join Date
    Oct 2001
    Posts
    4

    Re: Syntax Error in Recordset

    Instead of doing "Select ...." directly define
    a string type:

    Dim str1 as string

    and use str1 as the parameter to the call.


    dkj kaj hj sj

  4. #4
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: Syntax Error in Recordset

    What if you take of ";"?


    ===================
    "Select * From User Where UserName = '" & txtUserName.Text & "'"
    ====================

    Regards,

    Michi

  5. #5
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Syntax Error in Recordset

    I think User is a reserved word so try putting square brackets around it.

    rstAdo.Open "Select * From [User] Where UserName = '" & txtUserName.Text & "';", conAdo, adOpenStatic, adLockOptimistic, adCmdText

    David Paulson


  6. #6
    Join Date
    Sep 2001
    Posts
    16

    Re: Syntax Error in Recordset

    Hi,
    U change the name of the Table other than User.
    ex: User1 and try.

    Bye
    sunil.


  7. #7
    Join Date
    Oct 2001
    Posts
    3

    Re: Syntax Error in Recordset

    Michi is right in this case!


  8. #8
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Syntax Error in Recordset

    User is a keyword in SQL, and therefore cannot be used as a table name. If you do use it as a table name, you must enclose it in [ ] like d.paulson said.

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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

Featured