Syntax error in number - ODBC.

Syntax error in number - ODBC.

Post by Matt Swensso » Sun, 06 Feb 2000 04:00:00



Win95/98/NT
VC++5.0
SDI app w/database (Access 97, ODBC)

I am having a strange problem.  The user selects print from the main menu.
My printing functions work great except one part.  I open a recordset (one
is already open pointing to one table, but this is another table).  I use
the following code:

myset.m_strFilter.Format("UserID = %ld",id); //  id is a long.
if(!myset.IsOpen())
    myset.Open(CRecordset::dynaset);

this is all in a try/catch block.

It catches an error stating
    Syntax error in number in query 'UserID = 494'

I have tried putting in a number (i.e. 1, 2, 100) but I get the same result.
The strangest part is that if I put a goto in the catch and go back up to
the same line the exception is thrown (opening the recordset) it works fine!

Basically, what is happening is that whenever I try to open a table with a
query that uses a number (if I filter with a string it is fine) it doesn't
work, but every query after does.  If I were to skip this table, it gets
thrown on the next table I open, but fine after that.  It doesn't happen
anywhere else in my program (i can open and close a bunch of tables, but
when I want to go print and change to this view[a derived crecordview], it
acts funny the first time, but then is fine.)  All the views I use and
change between are derived crecordviews.

Anyone have any idea what the hell is wrong?  When an exception is thrown,
does the connection to the database get cleaned or something?  My initial
query is completely valid too, there is no illeagle characters in the
string.  I am sure of that because it works the second time.

Thanks,
    Matt

 
 
 

Syntax error in number - ODBC.

Post by Robert Quir » Sun, 06 Feb 2000 04:00:00


I'm not sure what is going on but I can give you some pointers ...

First of all there is no problem about your ommission of square brackets ..
you only need them if your column name has white space:

"[car registration] = 'N567YYY'"

try quoting the number with both single and double quotes:

myset.m_strFilter.Format("UserID = '%ld'",id) and
myset.m_strFilter.Format("UserID = \"%ld\"",id)

Now I hate the binding mechanism for the parameters in a recordset that's
why I write direct SQL !! but ...

1. Check the member variable m_nParams in your recordset is set to the
correct number of parameters you wish to bind. This is normally set in the
recordset's constructor.
2. Check that you have a statement
pFX->SetFieldType(CFieldExchange::inputParam) immediately before your RFX
function for the parameter binding
3. Check that your RFX function is of the desired type .. RFX_Long ? for the
param.

You can set a breakpoint the open statement

if(!myset.IsOpen())
 -->   myset.Open(CRecordset::dynaset);

and step into it (F11). It is very educational to see how the SQL string is
formed anyhow ... but if you step slowly and keep examining the SQL string
in your watch window you might see a syntax error creep into the SELECT
statement being built.


Quote:> Win95/98/NT
> VC++5.0
> SDI app w/database (Access 97, ODBC)

> I am having a strange problem.  The user selects print from the main menu.
> My printing functions work great except one part.  I open a recordset (one
> is already open pointing to one table, but this is another table).  I use
> the following code:

> myset.m_strFilter.Format("UserID = %ld",id); //  id is a long.
> if(!myset.IsOpen())
>     myset.Open(CRecordset::dynaset);

> this is all in a try/catch block.

> It catches an error stating
>     Syntax error in number in query 'UserID = 494'

> I have tried putting in a number (i.e. 1, 2, 100) but I get the same
result.
> The strangest part is that if I put a goto in the catch and go back up to
> the same line the exception is thrown (opening the recordset) it works
fine!

> Basically, what is happening is that whenever I try to open a table with a
> query that uses a number (if I filter with a string it is fine) it doesn't
> work, but every query after does.  If I were to skip this table, it gets
> thrown on the next table I open, but fine after that.  It doesn't happen
> anywhere else in my program (i can open and close a bunch of tables, but
> when I want to go print and change to this view[a derived crecordview], it
> acts funny the first time, but then is fine.)  All the views I use and
> change between are derived crecordviews.

> Anyone have any idea what the hell is wrong?  When an exception is thrown,
> does the connection to the database get cleaned or something?  My initial
> query is completely valid too, there is no illeagle characters in the
> string.  I am sure of that because it works the second time.

> Thanks,
>     Matt


 
 
 

Syntax error in number - ODBC.

Post by Werne » Thu, 10 Feb 2000 04:00:00


Look for article Q164954 at search.microsoft.com. Basically you need to clear a
pending floating point error with _fpreset().

> Win95/98/NT
> VC++5.0
> SDI app w/database (Access 97, ODBC)

> I am having a strange problem.  The user selects print from the main menu.
> My printing functions work great except one part.  I open a recordset (one
> is already open pointing to one table, but this is another table).  I use
> the following code:

> myset.m_strFilter.Format("UserID = %ld",id); //  id is a long.
> if(!myset.IsOpen())
>     myset.Open(CRecordset::dynaset);

> this is all in a try/catch block.

> It catches an error stating
>     Syntax error in number in query 'UserID = 494'

> I have tried putting in a number (i.e. 1, 2, 100) but I get the same result.
> The strangest part is that if I put a goto in the catch and go back up to
> the same line the exception is thrown (opening the recordset) it works fine!

> Basically, what is happening is that whenever I try to open a table with a
> query that uses a number (if I filter with a string it is fine) it doesn't
> work, but every query after does.  If I were to skip this table, it gets
> thrown on the next table I open, but fine after that.  It doesn't happen
> anywhere else in my program (i can open and close a bunch of tables, but
> when I want to go print and change to this view[a derived crecordview], it
> acts funny the first time, but then is fine.)  All the views I use and
> change between are derived crecordviews.

> Anyone have any idea what the hell is wrong?  When an exception is thrown,
> does the connection to the database get cleaned or something?  My initial
> query is completely valid too, there is no illeagle characters in the
> string.  I am sure of that because it works the second time.

> Thanks,
>     Matt

 
 
 

Syntax error in number - ODBC.

Post by Matt Swensso » Sat, 12 Feb 2000 04:00:00


thank you very much.  I bet this is my problem.

matt


> Look for article Q164954 at search.microsoft.com. Basically you need to
clear a
> pending floating point error with _fpreset().


> > Win95/98/NT
> > VC++5.0
> > SDI app w/database (Access 97, ODBC)

> > I am having a strange problem.  The user selects print from the main
menu.
> > My printing functions work great except one part.  I open a recordset
(one
> > is already open pointing to one table, but this is another table).  I
use
> > the following code:

> > myset.m_strFilter.Format("UserID = %ld",id); //  id is a long.
> > if(!myset.IsOpen())
> >     myset.Open(CRecordset::dynaset);

> > this is all in a try/catch block.

> > It catches an error stating
> >     Syntax error in number in query 'UserID = 494'

> > I have tried putting in a number (i.e. 1, 2, 100) but I get the same
result.
> > The strangest part is that if I put a goto in the catch and go back up
to
> > the same line the exception is thrown (opening the recordset) it works
fine!

> > Basically, what is happening is that whenever I try to open a table with
a
> > query that uses a number (if I filter with a string it is fine) it
doesn't
> > work, but every query after does.  If I were to skip this table, it gets
> > thrown on the next table I open, but fine after that.  It doesn't happen
> > anywhere else in my program (i can open and close a bunch of tables, but
> > when I want to go print and change to this view[a derived crecordview],
it
> > acts funny the first time, but then is fine.)  All the views I use and
> > change between are derived crecordviews.

> > Anyone have any idea what the hell is wrong?  When an exception is
thrown,
> > does the connection to the database get cleaned or something?  My
initial
> > query is completely valid too, there is no illeagle characters in the
> > string.  I am sure of that because it works the second time.

> > Thanks,
> >     Matt

 
 
 

1. Syntax error in number - ODBC.

I'm kind of new to ODBC myself, but I thought field names needed []'s.
And maybe your numbers are stored as text.

"[UserID] = %ld" or "[UserID] = '%ld'"?

--
Lynn Wallace                          http://www.xmission.com/~lawall
Be patient!  It took us forty million years for us to develop a thumb.
 It'll probably take us forty million years to get it out of our ass.

2. matching word

3. wrong DAO error: Syntax error in number in query expression

4. => AVG(date) okay Access NOT SQL Server

5. odbc error(category :odbc,source:odbc sql server driver,number:S1T00)

6. DataEnvironment difficulty

7. Please Help ODBC Error Code = 37000 (Syntax error or access violation)

8. Crosstab report problem

9. Informix SE ODBC Errors using MS Access #-201 Syntax Error Occured

10. Error 3131 Syntax error in FROM clause - using SQL accessing external ODBC problem

11. Syntax error w/ no error in syntax.

12. What does syntax error in number means?

13. Phantom 3075 syntax error in number?