02-19-2020 01:12 PM
I am trying to modify a database record based on the ID number. I looked at the Database Update.vi example but it has the Condition input of "db tools update data.vi" wired to a constant "where %s='%s' and %s='%s' ". I cannot find anything that shows how to change one record based on the ID number.
02-19-2020 02:03 PM - edited 02-19-2020 02:04 PM
Simply wire a string constant to the condition input which is "WHERE ID = <DESIRED ID>". This is essentially the WHERE clause for your SQL statement. Make sure that 'ID' equals the column name of the column you are using and that "<DESIRED ID>" equals the actual user ID.
02-19-2020 02:46 PM
Since the <DESIRED ID> is not a constant, just concatenate strings to get the correct formatting?
02-19-2020 03:18 PM
This code snippit did not work.
02-19-2020 03:22 PM
What DB are you using?
02-19-2020 03:41 PM
Microsoft JET Database Engine.
02-19-2020 04:04 PM
Are you getting any errors? Is the ID field a string? Your syntax in the WHERE clause indicates it is a string column. Is ID a numeric column? If so, drop the quotes around the ID.
02-19-2020 05:15 PM
I dropped the quotes and no longer get any errors, but it changes all of the rows, only 5 fortunately, in the DB.
02-19-2020 05:28 PM
Did the 5 rows all have the same ID? IF so, it did what you asked. If not, then something would appear to be wrong with the WHERE clause. To be honest, I rarely use most of the VIs in the DB toolkit. I generally only use Open, Close, Execute, and Fetch. My applications include the actual SQL in the code. As a rule of thumb, I generally only use stored procedures in the DB. This provides a nice API to the DB and allows changes to the schema without requiring changes to the application provided I maintain the calling structure of the stored procedures.
02-21-2020 01:05 PM
I gave up on "db tools update data.vi" and modified the "Database Fetching.vi" to read my data. It looks a lot easier to change and write the data. Time will tell.