ehxz 发表于 2007-6-26 12:12:09

[转帖]如何动态改编数据窗口的数据源

<table cellspacing="0" cellpadding="0" width="96%" align="center" border="0"><tbody><tr bgcolor="#ffffff"><td height="30"><div align="left"><p align="center"><b><font face="宋体">如何动态改编数据窗口的数据源</font></b></p></div></td></tr></tbody></table><table cellspacing="0" cellpadding="0" width="96%" align="center" border="0"><tbody><tr><td>&nbsp;</td></tr><tr><td>This script demonstrates how to change the source of a Datawindow dynamically. </td></tr><tr><td></td></tr><tr><td>&nbsp;</td></tr><tr><td>Example: You want to switch from a SQL select to a procedure OR you want to change from one procedure to another OR from one select to another. It doesn't matter, as long as the source that you are changing to brings back the same result set as was originally defined for the Datawindow. </td></tr><tr><td>&nbsp;</td></tr><tr><td>Note1: You may change the source ONLY if the result set does not change (i.e., the number of, type of, and order of columns does not change.) </td></tr><tr><td>&nbsp;</td></tr><tr><td>Note2: You must predefine all possible arguments to the DataWindow ahead of time. Remember, just because you have an argument defined doesn't mean that you have to use it. But all necessary arguments must be pre-defined. Then the appropriate arguments are referenced by the select or the stored procedure. </td></tr><tr><td>&nbsp;</td></tr><tr><td>Note3: Update capability may be affected. For example, even if the new source brings back the same data as the old source, if the column names are different, your updateable column list will be invalid (because it was defined against the old columns, not the new). </td></tr><tr><td>&nbsp;</td></tr><tr><td>However, if the column names are the same, you should be able to redirect updates to the new table by doing a Modify on datawindow.table.updatetable. </td></tr><tr><td>&nbsp;</td></tr><tr><td>Example of changing from a select source to a stored procedure source </td></tr><tr><td>&nbsp;</td></tr><tr><td>1. Create a procedure in ASA using following syntax: </td></tr><tr><td>&nbsp;</td></tr><tr><td>CREATE procedure dbo.sp_test () as </td></tr><tr><td>select department.dept_id,department.dept_name,employee.emp_lname from </td></tr><tr><td>DBA.department,DBA.employee </td></tr><tr><td>&nbsp;</td></tr><tr><td>2. In PB, create a datawindow which has the same select statement as in the stored proc. </td></tr><tr><td>&nbsp;</td></tr><tr><td>3. Now, you can change the datasource in the script as follows: </td></tr><tr><td>&nbsp;</td></tr><tr><td>dept_name = "R&amp;D </td></tr><tr><td>&nbsp;</td></tr><tr><td>w_1.Modify("datawindow.table.select =' ' ) </td></tr><tr><td>&nbsp;</td></tr><tr><td>od_string = "datawindow.table.procedure = ' execute dbo.sp_test;0 ' </td></tr><tr><td>&nbsp;</td></tr><tr><td>rc = dw_1.Modify(mod_string) </td></tr><tr><td>&nbsp;</td></tr><tr><td>F rc = " THEN </td></tr><tr><td>&nbsp;</td></tr><tr><td>dw_1.Retrieve ( dept_name, name_str) </td></tr><tr><td>&nbsp;</td></tr><tr><td>ELSE </td></tr><tr><td>&nbsp;</td></tr><tr><td>"Change to DW Source Failed) </td></tr><tr><td>&nbsp;</td></tr><tr><td>END IF </td></tr><tr><td>&nbsp;</td></tr><tr><td>* You can verify the change in the data source using 'dw_1.Object.Datawindow.Syntax' </td></tr><tr><td>in the script. </td></tr><tr><td>&nbsp;</td></tr><tr><td>The following steps demonstrate how to change the source of a Datawindow from select to stored procedure permanently: </td></tr><tr><td>&nbsp;</td></tr><tr><td>1) Export your Datawindow to a DOS file (using the Library Painter.) </td></tr><tr><td>&nbsp;</td></tr><tr><td>2) Make a backup copy of the original file (in case you make a mistake and need to drop back!) </td></tr><tr><td>&nbsp;</td></tr><tr><td>) Using a text editor like Write or Notepad, open the file and replace the"retrieve = ... </td></tr><tr><td>line. Using the above example, the "retrieve = line in my datawindow source code might look like this: </td></tr><tr><td>&nbsp;</td></tr><tr><td>epartment.dept_id~" )) ) </td></tr><tr><td>&nbsp;</td></tr><tr><td>line in the Datawindow source code with the following "procedure = line (assumes the proc is owned by dbo) </td></tr><tr><td>&nbsp;</td></tr><tr><td>rocedure="execute dbo.sp_test;0 </td></tr><tr><td>&nbsp;</td></tr><tr><td>After making the change, you would import the modified source code back into your PBL. That's it! </td></tr><tr><td>&nbsp;</td></tr><tr><td>Again, always be sure to make a backup copy of your Datawindow before you import any changes (just in case you inadvertently make a bad change to the source code.)</td></tr><tr><td></td></tr><tr><td></td></tr><center><tr><td width="100%" bgcolor="#f8f8f8"><font color="#ffffff"></font></td></tr></center></tbody></table><p>&nbsp;</p>

lovelyni 发表于 2007-12-19 22:11:33

不错
页: [1]
查看完整版本: [转帖]如何动态改编数据窗口的数据源

免责声明:
本站所发布的一切破解补丁、注册机和注册信息及软件的解密分析文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:Admin@SybaseBbs.com