| |

VerySource

 Forgot password?
 Register
Search
View: 910|Reply: 7

Syntax error near keyword 'xxx' ... crazy ... online etc.

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-19 23:00:02
| Show all posts |Read mode
Everyone big, quickly help the younger, for the database I want to write it as a DLL:

CADODatabase :: CADODatabase ()
{
    :: CoInitialize (0);
    m_pConnect.CreateInstance (__ uuidof (Connection));
    m_pConnect-> ConnectionString = "Provider = SQLOLEDB.1; Integrated Security = SSPI;\
        Persist Security Info = False; Initial Catalog = NetDisk; Data Source = 127.0.0.1 ";
    m_pConnect-> Open ("", "", "", -1);
}

CADODatabase :: ~ CADODatabase ()
{
    m_pConnect-> Close ();
    m_pConnect.Release ();
    :: CoUninitialize ();
}

// Judge if the user is legal.
bool CADODatabase :: JudgeLogIn (CString strUsername, CString strPassword, CString strTableName)
{
    if (FAILED (m_pRecordset.CreateInstance (__ uuidof (Recordset))))
    {
        return false;
    }

    CString strQuery;
    strQuery.Format (_T ("select * from% s where% s.Username =\'% s\' AND\
                       % s.Password =\'% s\' "), strTableName, strTableName,
                       strUsername, strTableName, strPassword);

    try
    {
        m_pRecordset-> Open (_bstr_t (strQuery),
            _variant_t ((IDispatch *) m_pConnect, true), adOpenStatic,
            adLockOptimistic, adCmdTable);

        m_pRecordset-> MoveFirst ();
        if (m_pRecordset-> adoEOF == VARIANT_FALSE)
        {
            return true;
        }
        return false;
    }
    catch (_com_error&e)
    {
        AfxMessageBox (e.Description ());
    }

    m_pRecordset-> Close ();
    m_pRecordset.Release ();
    return false;
}

I always throw an exception at m_pRecordset-> Open, and then I get an error description: "There is a syntax error near the keyword 'select'", but when I stepped into this step, COPY the value of strQuery to Query the analyzer, and then executed it ... but speechless ... Why is that?
Reply

Use magic Report

0

Threads

55

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-4-28 02:45:01
| Show all posts
\'% s\' Is it appropriate to see this kind of gratitude?
Reply

Use magic Report

0

Threads

10

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-4-28 21:30:02
| Show all posts
strQuery.Format (_T ("select * from% s where% s.Username =\'% s\' AND\
                       % s.Password =\'% s\' "), strTableName, strTableName,
                       strUsername, strTableName, strPassword);
-> strQuery.Format (_T ("select * from% s where% s.Username = '% s' AND
                       % s.Password = '% s' "), strTableName, strTableName,
                       strUsername, strTableName, strPassword);
Give it a try
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-4-29 11:00:02
| Show all posts
This error is generally a SQL syntax error.
Copy the value of strQuery to the database tool and execute it directly to see what strQuery is
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-5-14 10:45:01
| Show all posts
m_pRecordset-> Open (_bstr_t (strQuery),
            _variant_t ((IDispatch *) m_pConnect, true), adOpenStatic,
            adLockOptimistic, adCmdTable);
Change to
m_pRecordset-> Open (_variant_t ((CString) strQuery)
            _variant_t ((IDispatch *) m_pConnect, true), adOpenStatic,
            adLockOptimistic, adCmdTable);
Try
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-6-1 06:45:01
| Show all posts
I have written a new class. It is okay not to inherit from MFC's CObject. Is the same code because it cannot be inherited from CObject? ~~
Reply

Use magic Report

0

Threads

13

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-7-8 00:30:01
| Show all posts
Your sql statement is wrong after format, to have a look at messageBox, adCmdTable should be adCmdText, change to
strQuery.Format(_T("select * from %s where %s.Username ='%s' AND
                       %s.Password ='%s'"), strTableName, strTableName,
                       strUsername, strTableName, strPassword) Try it
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-8 09:45:01
| Show all posts
Password is a reserved word of SQLServer, you change the field name
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list