Home > database >  PB in the DataStore is a good thing
PB in the DataStore is a good thing

Time:10-08



Programming process to add a drop-down list to the window (DDLB), originally heard students say can dynamically change the value of the drop-down list in the database table change, client drop-down list at the front desk will change, remember the classmate say a call with a dropdown data window (DDDW) what to do, hasn't been tried, encountered such a problem today, want to have a try, so look for example on the net, but it seems that is not my meaning, said the following simple requirements:


Involved in table: 1, dm_yhzl (bank sort code table)


Fields: yhzl _dm (bank sort code, such as 1100120), yhzl_mc (bank species names, such as industrial and commercial bank of China)


2, dm_yh (bank name code table)


Fields: yhzl_dm (bank sort code), yh_dm (bank code, such as 1101, etc.), yh_mc (specific bank name)


Requirements: window has a drop-down list, all the Banks in the inside of the ITEM contains dm_yhzl species, the contents of the drop-down list as Banks increases with increasing data type in the code table, and then the specific bank information in the data window for the bank of the drop-down list, all kinds of information, such as





Implementation: listen to the classmate say DDDW access can be connected to a data table, want to try to get start, but it seems that DDDW can only be used in the data window, such as Freeform types of data window, but I want to look at the window of DDLB, so don't meet my needs, so think of the way with the cursor, so the use of the Internet query cursor (originally used, small white), but PBer seem to reflect the cursor is not working, query speed is slow, it is recommended to use DataStore to replace cursor, and then exposed to new things: DataStore (ha, small white once again), according to the online presentation, feeling should be able to meet my needs, so try to make up,





The first step is to create a data window (Grid), choose dm_yhzl two columns in a table, such as filters can be installed where conditions needed, called dw_yhzl,


The second step, and then create a Grid type the bank information of the data window, select the yh_dm dm_yh and yh_mc columns, called dw_yh,


Third step, the drop-down list is added in the window control (DDLB), called ddlb_yhzl, add data window control, below the corresponding data window for the created dw_yh,


The fourth step, in the open event window control to write the following code:


String ls_yhzl


Long ll_row, ll_row_count





Datastore ds_yhzl//statement datastore variable


Ds_yhzl=create datastore//the datastore instantiation


Ds_yhzl. Dataobject="dw_yhzl"//for the datastore distribution data window object


Ds_yhzl. Settransobject (sqlca)//specified connection instance


Ds_yhzl. Retrieve ()//extract data





Ll_row_count=ds_yhzl. Rowcount ()//will take data rows are stored in ll_row_count variable





For ll_row=1 to ll_row_count//create a loop statement values


Ls_yhzl=ds_yhzl. Getitemstring (ll_row, "yhzl_mc")//get the current row yhzl_mc field corresponding values


Ddlb_yhzl. Additem (ls_yhzl)//will take to the current row of value added to the dropdown list


Next//remove a record


Destroy ds_yhzl//release the datastore





Through the above operation, controls the open window, the drop-down list automatically add the bank sort code table of all types of Banks, bank types under specific bank information, you can add the query button to add the following code in query button clicked events (also can be added in the drop-down list the selectionchanged event, but are too many data may be slower) :


String old_select setselect, setwhere


Old_select=dw_1. The describe (" datawindow. Table. Sqlselect ")//SQL statement in the current data window variable old_select


Setselect="select yh_dm, yh_mc from dm_yhzl a, dm_yh b"//set the select statement, pay attention to the double quotation marks to add a space before


Setwhere="a.y hzl_dm=b.y hzl_dm"//set the where condition


If the trim (ddlb_yhzl. Text) & lt;> "' then//if the drop-down list, select the types of Banks, to join the following conditional statement in the query conditions


Setwhere +="and a.y hzl_mc='" + ddbl_yhzl. Text +"' "


End the if


Dw_1. Object. Datawindow. Table. Select=setselect + setwhere//dynamic modify the data window query


Dw_1. Settransobject (sqlca)//specified connection instance


Dw_1. Retrieve ()//to extract data on the revised terms and conditions


Dw_1. Object. Datawindow. Table. Select=old_select//the data window query reset to the original query



Well, you're done, run the program, open the window, the drop-down list in all types of Banks, such as not to choose, click the query button, the data window shows all the bank information, such as icbc's branches, each branch of CCB, the branch of agricultural bank, etc., if the selection of the industrial and commercial bank of China in the bank, click the query button control, is to list the branch of icbc information,
  • Related