ATTENTION

This 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

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
FAQ Downloads Calendar Search Mark Forums Read

Q&A Using Flexsim and building models

Reply
 
Thread Tools Display Modes
  #1  
Old 10-20-2010
mutyisi mutyisi is offline
Flexsim User
 
Join Date: Sep 2010
Posts: 8
Downloads: 15
Uploads: 0
Thanks: 4
Thanked 0 Times in 0 Posts
Rep Power: 0
mutyisi is on a distinguished road
Default 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.



Reply With Quote
  #2  
Old 10-20-2010
AJ Bobo's Avatar
AJ Bobo AJ Bobo is offline
Flexsim Senior Developer
 
Join Date: Jul 2007
Posts: 108
Downloads: 8
Uploads: 0
Thanks: 23
Thanked 89 Times in 41 Posts
Rep Power: 218
AJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the rough
Default

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.
Reply With Quote
  #3  
Old 10-25-2010
AJ Bobo's Avatar
AJ Bobo AJ Bobo is offline
Flexsim Senior Developer
 
Join Date: Jul 2007
Posts: 108
Downloads: 8
Uploads: 0
Thanks: 23
Thanked 89 Times in 41 Posts
Rep Power: 218
AJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the rough
Default

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();
Reply With Quote
The Following 2 Users Say Thank You to AJ Bobo For This Useful Post:
Jason Lightfoot (10-25-2010), RalfGruber (10-25-2010)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 11:40 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.