Hello All.
I am trying to append some data from an excel sheet to a table .I make Sql connection to the excel sheet ,run a "Select" query and then loop through resultset and enter the new records .
The query runs fine and I get the resultset with no errors ,but Alpha hangs when I loop through the results after entering 400 to 700 records .
I Can not figure out whats wrong .Any help or guidance is truly appreciated, I have spent days on the problem.
Here is my code
Thanks Nick.
I am trying to append some data from an excel sheet to a table .I make Sql connection to the excel sheet ,run a "Select" query and then loop through resultset and enter the new records .
The query runs fine and I get the resultset with no errors ,but Alpha hangs when I loop through the results after entering 400 to 700 records .
I Can not figure out whats wrong .Any help or guidance is truly appreciated, I have spent days on the problem.
Here is my code
Code:
DIM cn as SQL::Connection dim flagResult as l flagResult = cn.open("{A5API='Excel',A5Syntax='Excel',FileName='C:\user_private\os_main.xlsx', A5ExcelVersion=2007}") if flagResult = .f. then ui_msg_box("Error","Could not connect to database. Error reported was: " + crlf() + cn.CallResult.text) end end if cn.PortableSQLEnabled = .t. dim sqlStatement as c sqlStatement = <<%sql% SELECT src.[Supplier SKU] AS Supplier_SKU, src.Description, src.[Unity Nick, Inc# Inventory on hand] AS Unity_Nick_Inc_Inventory_on_hand FROM [Sheet0$] src ORDER BY src.[Supplier SKU] %sql% 'Execute the Query flagResult = cn.Execute(sqlStatement) if flagResult = .f. then ui_msg_box("Error",cn.CallResult.text) cn.close() end end if dim rs as sql::resultset rs = cn.ResultSet dim flagLoop as l flagLoop = .t. dim xls_src as p xls_src=table.open("os_main") xls_src.zap(.t.) xls_src.pack() while flagLoop on error goto close_script xls_src.enter_begin() xls_src.partner_sku=right(alltrim(rs.Data(1)),20) xls_src.option_name=right(alltrim(rs.Data(2)),56) xls_src.quantity_on_hand=val(alltrim(rs.Data(3))) xls_src.enter_end() on error goto 0 flagLoop = rs.NextRow() end While debug(1) cn.close() xls_src.close() end close_script: msgbox("",error_text_get()) xls_src.enter_end(.f.) xls_src.close() cn.close()
Comment