If you connect the DB using ODBC, you might want to store the data you want to DB.
1. Store the actual data coming from the site in the DB every time.
2. The user clicks the button to save the data to the DB
Example)
1. Save the actual data coming from the site to the DB every time.
1) First, write a table to be stored in the DB and set up a 32-bit ODBC connection in the control panel (Reference: Editer|File|SQL Connection Setup (AccessSQL))
2) If configured as above, the initial preparation is complete. Next, the user must specify the tag name to be saved and the field name and connection setting to be stored in the DB's Table in the editor | preference | SQL connection setting.
You can set up the SQL connection as shown in the picture below. (The file name below is called bindlist, for example.)
When explaining the above figure, the user created and configured the fields of YMDHM (date), DATA1, DATA2, DATA3, and DATA4 in the DB table, and the YMDHM string tag of the localmain and the analog tag values of AI_0001, AI_0002, AI_0003, and AI_0004 are connected to this field. When configured as above and "SQLInsert (Argument1, Argument2, Argument3);" is used, the values of the analog tag/string tag are stored in the specified field.
3) Next, you need to write a script. If the user saves data every two seconds, the script is written as follows in the Editor|File|Script editing to 'Script when program running' script because the data must be continuously uploaded at regular intervals during executing the localmain.
When the script is written as above, the current time is stored in a string tag called YMDHD every two seconds, and the tags (called bindlist) connected in the SQL connection setting are stored in the DB using @SQLInsert().
To explain the contents of the script, the program above is executed once every two seconds because the scantime is set to 2 seconds.
year=@GetDateYear(); //Load the year of current saving time
mon=@GetDateMon(); //Load the month of current saving time
day=@GetDateDay(); //Load the day of current saving time
Hour=@GetTimeHour(); //Load the hour of current saving time
min=@GetTimeMin(); //Load the minute of current saving time
@sprintf($YMDHM, "%04d/%02d/%02d-%02d:%02d",year,mon,day,hour,min); //The imported current time is stored in the string tag YMDHM (for example, year=2000, mon=9, day=13, hour=9, min=27),
and the value stored in YMDHM is ¡°
ID=@SQLConnect("autobase", "", ""); //This function connects to ODBC. The ID type must consist of DWORD.
@SQLInsert(ID, "Table1","bindlist"); //This function adds (saves) the bindlists specified in the SQL connection setting to the table of the connected DB.
@SQLDisconnect(ID); //This disconnects from the DB.
2. Users click a button to save data to DB
1) This content is the same up to contents 1) and 2) above. Therefore, contents 1) and 2) above are performed.
2) The following is a different place to write a script. For the above, I put the script in 'Continue while running a localmain program', but this time I use the 'Script button' on the Editor | Object | Button. The contents of the program are the same as those organized in 3) above.