How to read the data of Excel spreadsheet in PB and ASP
Yang Jichun
Xi'an 505 Mailbox 14
In Power Builder, although interfaces with Excel spreadshes are provided in the ODBC settings, since Excel's structures are relatively special,, if they are connected to the general database connection, "Syntax Error from Clause" occurs when reading data. "The error, the reason, is due to the sheet1, sheet2, sheet3 in the left lower corner of the spreadsheet, is not a true table name, so it does not find the wrong error when the data is transmitted, in order to read in PB Take the data of the spreadsheet, we need to work as follows:
Suppose there is an Excel spreadsheet, named myData.xls, open the spreadsheet, select the required row and column, then press the insert / name / definition on the menu, pop up a dialog box that defines the name, we give it The selected data defines a table name, such as Work, in a reference location at the lower end of the dialog, "= sheet1! $ 1 $ 1: $ C $ 22", means that the list defined for this table name is Sheet1 The first line in the first line to the third column 22 line, if you want to choose all the rows, just change it to "= sheet1! $ A: $ C". Then press OK so that we will define the name to the selected ranks. Then we connect the database in the PB panel, and select the data in the Excel spreadsheet from which you just defined. If you need to dynamically read in the program, simply add the following statements in the program:
Sqlca.dbms = ProfileString ("Pb.ini", "Database", "DBMS", "")
Sqlca.Database = ProfileString ("Pb.ini", "Database", "Database", "")
SQLCA.DBPARM = ProfileString ("Pb.ini", "Database", "DBPARM", "")
CONNECT Using SQLCA;
IF SQLCA.SQLCODE <0 THEN
MessageBox ("Error Message", "Connection Database Failed!")
Return
END IF
Then select * from Work in the SELECT *.
The method of reading the data in the Excel spreadsheet in the ASP, and the method read in the PB is basically the same, and only the program read the database can be changed to the following statements.
Set conn = server.creatobject ("adoDb.connection")
Conn.open "MyData"
SET Connstr = Server.creatObject ("AdoDb.Recordset")
Connstr.Source = "SELECT * from Work"
Connstr.open