ATTENTIONThis FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices. |
flexsim.com |
#1
|
|||
|
|||
Problem with using dbsettablenum
Hi all,
I am having trouble making the dbsettablenum function work. I have the db open in table mode. Its not writing anything to the database. Here is part of my code: dbsettablenum(index,3,value); index and value are variables and i put some print statements before the dbsettablenum command to see if they have values other than 0 and they had nonzero values. If I hard code the dbsettablenum command with numbers instead of variables, it works. For instance: dbsettablenum(1,3,100); I just can't understand why dbsettablenum won't work. On the other hand if I alternatively open the database in sql mode and use sql queries to update the database, it also works but the problem is that the operations are costly on the execution speed. |
#2
|
||||
|
||||
There are a couple of things to check to solve this problem:
1) Make sure that the cell that you are trying to write to has number data in it, not text. 2) Make sure that the variable being passed in as the value is a number not a string. 3) Make sure the ODBC data source is not set as Read-Only. This is a setting that may be hidden behind an "Advanced" button in the data source configuration GUI. If none of those seem to be the problem, can you post more of your code? Maybe there's something else going on in this function that's stopping the database from updating properly. Thanks. |
#3
|
||||
|
||||
Someone else recently reported a problem similar to this with MySQL that had a simple solution. Maybe this will help you too:
After you write a batch of data to the table, call dbchangetable(), passing it the name of the table that you just changed, before you try to read from the table again. Apparently, the database is actually being updated by the dbsettablenum() call, but the table that's loaded in Flexsim's memory isn't. Calling dbchangetable() will force Flexsim to update the table in memory. For example: Code:
dbopen("MyDB","Table1",1,0); for (int x = 1; x <= dbgetnumrows(); x++) { // Write to the table dbsettablenum(x,1,x * 3); } dbchangetable("Table1"); // Update the table in memory for (int x = 1; x <= dbgetnumrows(); x++) { // Print the new table entries pd(x); pt(": "); pf(dbgettablenum(x,1)); pr(); } dbclose(); |
The Following 2 Users Say Thank You to AJ Bobo For This Useful Post: | ||
RalfGruber (10-25-2010) |