Database Update Problem

Just starting out? Need help? Post your questions and find answers here.
shire
User
User
Posts: 46
Joined: Mon Jul 25, 2011 5:24 am

Database Update Problem

Post by shire »

Hello,

I'm using ODBC Connection and I'm having a problem updating record in the database, here's the code:

Code: Select all

Table$ = "name"
cn$ = GetGadgetText(173)
father_fname$ = (GetGadgetText(174)
result = DatabaseUpdate(0, "UPDATE "+Table$+" SET fname='"+father_fname$+"' WHERE MT1_F17 = '"+cn$+"';") 
It also has the result = 1, but it does not update the record. What could have been wrong?
Any idea?
Your answers will be very much appreciated.
Thank you:)
Last edited by shire on Wed Aug 17, 2011 7:21 am, edited 1 time in total.
jamba
Enthusiast
Enthusiast
Posts: 144
Joined: Fri Jan 15, 2010 2:03 pm
Location: Triad, NC
Contact:

Re: Database Update Problem

Post by jamba »

what's your table structure?

how are you connecting to db?

does databaseError() return anything?
-Jon

Fedora user
But I work with Win7
shire
User
User
Posts: 46
Joined: Mon Jul 25, 2011 5:24 am

Re: Database Update Problem

Post by shire »

Hello jamba,

My table structure looks like this:
+-------------+-----------------+--------------+
| table_name | column_name | data_type |
+-------------+-----------------+--------------+
| name | F1 | varchar(10) |
| name | F2 | varchar(30) |

and I use this code to connect to the database:

Code: Select all

UseODBCDatabase()
   DriverODBC.s = "MySQL" 
   root$ ="root"
   pwd$ = "password"
OpenDatabase(0, DriverODBC, root$, pwd$)
I only have this update problem when using variable which is assigned with the value of a text coming from a gadget like the code I posted.
Inserting data works fine, and databaseError() returns nothing.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4790
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Database Update Problem

Post by Fangbeast »

Code: Select all

Table$ = "name"
cn$ = GetGadgetText(173)
spouse_fname$ = (GetGadgetText(174)
result = DatabaseUpdate(0, "UPDATE "+Table$+" SET fname='"+father_fname$+"' WHERE MT1_F17 = '"+cn$+"';")
Not sure if your typos are accidental or not but...

1. spouse_fname$ = (GetGadgetText(174) is an error and pb should have warned you that you have a bracket in front of GetGadgetText.

2. You get a value into spouse_fname$ in your above example but in your database statement you are passing father_fname$,
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
shire
User
User
Posts: 46
Joined: Mon Jul 25, 2011 5:24 am

Re: Database Update Problem

Post by shire »

@fangbeast:
oh, sorry! typo error..
that should be,

Code: Select all

Table$ = "name"
cn$ = GetGadgetText(173)
father_fname$ = GetGadgetText(174)
result = DatabaseUpdate(0, "UPDATE "+Table$+" SET fname='"+father_fname$+"' WHERE MT1_F17 = '"+cn$+"';")
btw, thank you for the reply:)
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: Database Update Problem

Post by citystate »

Code: Select all

+-------------+-----------------+--------------+
| table_name  | column_name     | data_type    |
+-------------+-----------------+--------------+
| name        | F1              | varchar(10)  |
| name        | F2              | varchar(30)  |
according to the structure you gave, the only fields are F1 and F2 - where do fname and MT1_F17 come into it?
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
shire
User
User
Posts: 46
Joined: Mon Jul 25, 2011 5:24 am

Re: Database Update Problem

Post by shire »

Hello enthusiast,

Sorry for that,
it was suppose to be:
fname = F1
MT1_F17 = F2

Here's the exact structure

Code: Select all

+-------------+-----------------+--------------+
| table_name  | column_name | data_type   |
+-------------+-----------------+--------------+
| name        | MT1_F17          | varchar(10) |
| name        | fname             | varchar(30) |
:)
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: Database Update Problem

Post by citystate »

perhaps add this line

Code: Select all

result = DatabaseUpdate(0, "COMMIT;")
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
shire
User
User
Posts: 46
Joined: Mon Jul 25, 2011 5:24 am

Re: Database Update Problem

Post by shire »

Thank you citystate:) I'll try it..
shire
User
User
Posts: 46
Joined: Mon Jul 25, 2011 5:24 am

Re: Database Update Problem

Post by shire »

Thank you for all the reply:) it's finally working..
Post Reply