Three ways to realize data windows in PB

xiaoxiao2021-03-06  97

The data used to retrieve the data window in PowerBuilder is often disordered, although the sequencing function can be achieved by setting the SELECT statement, but the data window cannot be dynamically adjusted. The author summarizes three ways to realize dynamic sorting in the generated data window, which is now introduced to everyone.

First, ready to work

The description is designed as shown in Figure 1. In order to better compare three different methods, the data in DW-1 comes from two tables Student and Class. The Student table contains four fields SID (student number), SNAME (Name), Saddr (address), and CID (class number), including two field CIDs (class numbers) and CNAME (class name).

figure 1

Second, three ways of source

The code of the "Executive" button in the three methods is: method 1: use setsqlselect ()

String LS-Oldsql, LS-Newsql, LS-Order LS-Column LS-Oldsql = DW-1.Getsqlselect () Choose Case DDLB-1.Text Case "LS-Column =" SID "Case" Name "LS -COLUMN = "Sname" Case "address" LS-Column = "Saddr" Case "class" LS-column = "Class.cid" Case "class name" LS-column = "cname" End Choose if RB-1. Checked THEN LS-ORDER = "ASC" Else Ls-Order = "DESC" end if ls-newsql = LS-Oldsql " LS-ORDER IF DW-1.Setsqlselect (LS-Newsql) ) = - 1 THEN MessageBox ("Warning", "Data Setup Failure", Stopsign!) Else DW-1.SetTransobject (SQLCA) DW-1.Reset () DW-1.Retrieve () DW-1.setsqlselect (LS -OLDSQL) END IF Method 2: Use describe () and modify ()

String LS-MOD, LS-Order, LS-OLD, LS-Column LS-OLD = DW-1.Describe ('DataWindow.Table.Select') DW-1.SetTransObject (SQLCA) Choose Case DDLB-1.Text Case "Learn" LS-Column = "SID" case "name" LS-color = "SNAME" Case "address" LS-Column = "Saddr" Case "class" ls-color = "Class.cid" Case "class Name "ls-color =" cname "end choose if rb-1.checked the ls-order =" ASC "ELSE LS-ORDER =" DESC "end if ls-mod =" dataWindow.table.select = '" ls- Old & 'Order By "' LS-Column '"' LS-ORDER "" DW-1.Modify (LS-MOD) DW-1.Modify () DW-1.Modify ("DataWindow.Table.Select = & ' " LS-OLD " '") Method 3: Use setort () and sort ()

String LS-SORT, LS-Order, LS-Column Choose Case DDLB-1.Text Case "LS-Column =" # 1 "Case" name "LS-color =" # 2 "Case" Address "LS- Column = "# 3" Case "class" ls-color = "# 4" Case "class name" ls-color = "# 5" END Choose if rb-1.checked the ls-order = "a" ELSE LS -Order = "D" end if ls-sort = ls-color DW-1.Setsort (LS-SORT) DW-1.Sort () three, three methods comparison

1. The first and second methods require that the data window is generated, and the third method has no such requirements. 2. For the same column name (such as student.cid, class.cid) from different forms, it is more troublesome to use the second method because it takes special attention to the use of quotation marks when using the Modify () function. However, the second method is faster than the execution speed of the first method. 3. The third method is used to use it easier, which can specify the sequence (such as a # 4 representation of the fourth column).

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

New Post(0)