DAO update problem 
Author Message
 DAO update problem

I'm trying to update my database with the following, but
I get a Syntax error in UPDATE statement error. Why?

        CString sql = "UPDATE Kund SET Namn=\"" + name
+ "\", Banknr=" + bank + ", Kontonr=" + accountNr + ",
Adress=\"" + address + "\", Postnr=" + (CString) itoa
(postalNr, apa, 10) + ", Ort=\"" + city + "\" WHERE
Kundnr=" + (CString) ltoa(nr, apa, 10);
        database.Execute(sql);



Sat, 10 Sep 2005 09:22:10 GMT  
 DAO update problem

Quote:

> I'm trying to update my database with the following, but
> I get a Syntax error in UPDATE statement error. Why?

>    CString sql = "UPDATE Kund SET Namn=\"" + name
> + "\", Banknr=" + bank + ", Kontonr=" + accountNr + ",
> Adress=\"" + address + "\", Postnr=" + (CString) itoa
> (postalNr, apa, 10) + ", Ort=\"" + city + "\" WHERE
> Kundnr=" + (CString) ltoa(nr, apa, 10);
>    database.Execute(sql);

First, I would use the CString::Format() to create the SQL string. I find
it easier to work with and to read.

The error is probably that you are using \" round string values. I think
you need to use \'

Hope this will help you!

// Anders



Sat, 10 Sep 2005 10:22:50 GMT  
 DAO update problem

Quote:
>-----Original Message-----

>> I'm trying to update my database with the following,
but
>> I get a Syntax error in UPDATE statement error. Why?

>>        CString sql = "UPDATE Kund SET Namn=\"" + name
>> + "\", Banknr=" + bank + ", Kontonr=" + accountNr + ",
>> Adress=\"" + address + "\", Postnr=" + (CString) itoa
>> (postalNr, apa, 10) + ", Ort=\"" + city + "\" WHERE
>> Kundnr=" + (CString) ltoa(nr, apa, 10);
>>        database.Execute(sql);

>First, I would use the CString::Format() to create the
SQL string. I find
>it easier to work with and to read.

>The error is probably that you are using \" round string
values. I think
>you need to use \'

>Hope this will help you!

>// Anders
>.

Thanks for your reply Anders,

however it didn't help. I suspect now it has something to
do with the '(CString) ltoa(nr, apa, 10);' part of the
sql CString assignment. It is only giving me the first
digit of a number of digits that exist in the database.
Any suggestion?



Sat, 10 Sep 2005 11:40:19 GMT  
 DAO update problem

Quote:
>-----Original Message-----

>> I'm trying to update my database with the following,
but
>> I get a Syntax error in UPDATE statement error. Why?

>>        CString sql = "UPDATE Kund SET Namn=\"" + name
>> + "\", Banknr=" + bank + ", Kontonr=" + accountNr + ",
>> Adress=\"" + address + "\", Postnr=" + (CString) itoa
>> (postalNr, apa, 10) + ", Ort=\"" + city + "\" WHERE
>> Kundnr=" + (CString) ltoa(nr, apa, 10);
>>        database.Execute(sql);

>First, I would use the CString::Format() to create the
SQL string. I find
>it easier to work with and to read.

>The error is probably that you are using \" round string
values. I think
>you need to use \'

>Hope this will help you!

>// Anders
>.

The sql query I get is:

UPDATE Kund SET Namn='Nisse', Banknr='12345',
Kontonr='54321', Adress='Nissev', Postnr=12345,
Ort='Nisseborg', Vxl='true', Best='false', Inl='false'
WHERE Kundnr=12345

And in the Access database
Namn, Banknr, Kontonr, Adress, Ort is of type Text
Postnr, Kundnr is of type Number
Vxl, Best, Inl is of type Yes/No



Sat, 10 Sep 2005 12:21:51 GMT  
 DAO update problem

Quote:

>>-----Original Message-----

>>> I'm trying to update my database with the following,
> but
>>> I get a Syntax error in UPDATE statement error. Why?
>>>    CString sql = "UPDATE Kund SET Namn=\"" + name
>>> + "\", Banknr=" + bank + ", Kontonr=" + accountNr + ",
>>> Adress=\"" + address + "\", Postnr=" + (CString) itoa
>>> (postalNr, apa, 10) + ", Ort=\"" + city + "\" WHERE
>>> Kundnr=" + (CString) ltoa(nr, apa, 10);
>>>    database.Execute(sql);

>>First, I would use the CString::Format() to create the
> SQL string. I find
>>it easier to work with and to read.

>>The error is probably that you are using \" round string
> values. I think
>>you need to use \'

>>Hope this will help you!

>>// Anders
>>.

> The sql query I get is:
> UPDATE Kund SET Namn='Nisse', Banknr='12345',
> Kontonr='54321', Adress='Nissev', Postnr=12345,
> Ort='Nisseborg', Vxl='true', Best='false', Inl='false'
> WHERE Kundnr=12345
> And in the Access database
> Namn, Banknr, Kontonr, Adress, Ort is of type Text
> Postnr, Kundnr is of type Number
> Vxl, Best, Inl is of type Yes/No

The error is that you are handling the Boolean fields (Vxl, Best, Inl) as
text. Remove the ' ' around true and false.

// Anders



Sat, 10 Sep 2005 23:03:05 GMT  
 DAO update problem

Quote:
>-----Original Message-----

>>>-----Original Message-----

>>>> I'm trying to update my database with the following,
>> but
>>>> I get a Syntax error in UPDATE statement error. Why?

>>>>        CString sql = "UPDATE Kund SET Namn=\"" + name
>>>> + "\", Banknr=" + bank + ", Kontonr=" + accountNr
+ ",
>>>> Adress=\"" + address + "\", Postnr=" + (CString) itoa
>>>> (postalNr, apa, 10) + ", Ort=\"" + city + "\" WHERE
>>>> Kundnr=" + (CString) ltoa(nr, apa, 10);
>>>>        database.Execute(sql);

>>>First, I would use the CString::Format() to create the
>> SQL string. I find
>>>it easier to work with and to read.

>>>The error is probably that you are using \" round
string
>> values. I think
>>>you need to use \'

>>>Hope this will help you!

>>>// Anders
>>>.

>> The sql query I get is:

>> UPDATE Kund SET Namn='Nisse', Banknr='12345',
>> Kontonr='54321', Adress='Nissev', Postnr=12345,
>> Ort='Nisseborg', Vxl='true', Best='false', Inl='false'
>> WHERE Kundnr=12345

>> And in the Access database
>> Namn, Banknr, Kontonr, Adress, Ort is of type Text
>> Postnr, Kundnr is of type Number
>> Vxl, Best, Inl is of type Yes/No

>The error is that you are handling the Boolean fields

(Vxl, Best, Inl) as

Quote:
>text. Remove the ' ' around true and false.

>// Anders
>.

It didn't help, I still get Syntax error in UPDATE
statement error.

/Joachim



Sun, 11 Sep 2005 16:04:08 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. DAO update problem

2. Oracle+DAO Interesting Problem in UPDATES

3. KB Q160554 PATCH: Updated DAO Redistributable Components - InstallShield.

4. MFC DAO - database update notifications...

5. NEWBIE: ODBC or DAO to read and update FoxPro dbf

6. DAO Update

7. Does ODBC/DAO provide update notifications?

8. Retrieving updated information only from MS Access Database w/ MFC DAO

9. USING RDO AND DAO; UPDATING DATA

10. DAO recordset AddNew and Update

11. Q: DAO Recordset updates in a multiuser environment

12. Update a text database with DAO

 

 
Powered by phpBB® Forum Software