Talking about the Technical Application of Dynamic DataWindow in PB

xiaoxiao2021-03-06  44

http://tech.sina.com.cn 2000/10/30

Software world

Yang Xiaoping

During the application development of PowerBuilder, the object to operate in the database is a data window object (DataWindow), using data window objects, we can easily complete the data in the table already existing in the database, query, Insert, delete, and update. However, in actual problems, we often encounter some tables in the database that users are generated during program operation. To operate the data in such a table, it is necessary to use dynamic data window objects, which is worth mentioning. Yes, when the dynamic data window object is generated, the text in the header band cannot be displayed directly as a Chinese character, which is indeed unfortunately, but this problem can be resolved by the mapping method. First, the problem is proposed with the following two tables: records in the table is that users can freely increase, modify, delete, and update during program operation (ie: fields) in the table. The record is determined and dynamically created, and it is convenient to provide the data in the B table to provide the Hanhua operation interface. Of course, it is also possible to create the B table as the following table, however, when dynamically generating a data window object, the text in the header band does not display Chinese characters, but some garbled, but not to solve the problem. . Second, the problem solving 1. Dynamically create the resolution of the B table We want to dynamically create a B table, you must build a dynamic SQL statement. What is dynamic SQL statement? Database applications typically determine the task, so you can determine the full SQL statement when writing and compile, but when you need to use the PowerBuilder unsupported SQL statement (such as DDL statement), or if you do not know the specific statement Format or parameters, the SQL statement is configured at runtime, which is called a dynamic SQL statement. Dynamic SQL statement format: Execute Immediate SQL Statement [Using Trans) Object]; Parameter Description: SQL Statement contains a string of the SQL statement TransArtion Object Transaction Object 2, Dynamic Data Window Object Creation and Title Area (Header Band) Chinese Solution (1) When the program is run, we can call the CREATE function to dynamically generate data window objects. The format is as follows: DataWindowControl.create (Syntax {, ErrorBuffer}) Parameter Description: DataWindowControl will in which data window control name Syntax data window object source code errorbuffer is used to save error information String (2) due to title The name of the text box is the name of the corresponding column of the corresponding column in the detail band, and the name of the column in the detail band is also the name of the corresponding table. Therefore, we can use the Cursor to take out the value of YWM and ZWM in the A table, and then use the mapping method to replace the text (Text) attribute of the text box in the header band, so that the title area (Header Band) The text of Chinese text boxes is shown as the corresponding Chinese character. Third, a simple example is in the environment of Powerbuilder 6.5 and MS SQL Server 6.5, using a simple example to achieve the above view, limited to space, only listing the main interfaces and key processes.

1. The code corresponding to the "Dynamic Creating B" button is: int Li_i = 1, li_count string ywm [], zdlx [], ls_temp, ls_sql // Use the cursor (CURSOR) to get YWM and ZDLX value from the table of the database And stored in array ywm [] and zdlx [] SELECT Count (*) Into: li_count from a; declare a_cur cursor for select ywm, zdlx from a order by ywm; open a_cur; fetch a_cur inTo: ywm [li_i],: ZDLX [li_i]; do while sqlca.sqlcode = 0 ls_temp = trim (zdlx [li_i]) choose case ls_temp case "1" ls_temp = "char (10)" Case "2" LS_TEMP = "Numeric (7, 2)" End choose zdlx [li_i] = ls_temp ywm [li_i] = trim (ywm [li_i]) li_i fetch a_cur @ i [[li_i],: zdlx [li_i]; loop close a_cur; // Create B table and primary key (Primary Key) ) Ls_sql = "CREATE TABLE B" "(" YWM [1] " ZDLX [1] " NOT NULL, "& " Constraint PK_B Primary Key (" YWM [1] ") " Execute immediate: ls_sql; // increase the column for the B table for Li_i = 2 to li_count ls_sql = "alter table b add" ywm [li_i] " zdlx [ls_sql; end for 2," Dynamics Creating a Data Window Object button The code is: string syntax, sqlselect, errmsg, ls_col1, ls_col2, ls_name, ls_b; // dynamically created data window object dataWindow ls_b = "b" sqlselect = "select * from" ls_b; Syntax = sqlca.synTaxfromsql (Sqlselect, "style (type = grid)", errmsg); dw_1.create (syntax) // Hanhua Title Area (Header Band) Text Declare V_Cur Cursor for Select Ywm, ZWM from a Order by YWM; Open v_cur; fetch v_cur inTo: ls_col1,: ls_col2; do while sqlca.sqlcode = 0 ls_name = LS_COL1 '_' '=' '"' ls_col2 '" DW_1.MODIFY (LS_NAME) FETCH V_CUR INTO: LS_COL1,: LS_COL2;

转载请注明原文地址:https://www.9cbs.com/read-79725.html

New Post(0)