How can I create a COM component in Pb, call it in ASP, and return the result set?

Source: Internet
Author: User
Start pb7.0 and create an invisible user object "uo_customer". Create an "object" and select "Custom class"
Type, click "OK ".
Write the following program in the newly created user object:
1. Declare the instance variable "instance variables". For types not supported in COM, declare it as protected type. Protected:
Datastore ds_datastore
2. Create three new member functions:
Int uf_connect () // used to link a database and create a datastore object.
Code:
Sqlca. DBMS = "ODBC"
Sqlca. Database = "webdw"
Sqlca. autocommit = false
Sqlca. dbparm = "connectstring = ''dsn = webdw; uid = DBA; Pwd = SQL ''"
Connect using sqlca;
Ds_datastore = create datastore
If sqlca. sqlcode = 0 then
Return 1
Else
Return-1
End if

Void uf_disconnect () // used to disconnect a database and release a datastore object.
If isvalid (ds_datastore) then destroy ds_datastore
Disconnect using sqlca;

Resultset uf_retrieve () // read customer information
Resultset lrs_customers
Ds_datastore.dataobject = "d_customer"
Ds_datastore.retrieve ()
Ds_datastore.generateresultset (lrs_customers) // generate a result set
Return lrs_customers // return result set
Finally, save the modified object as "uo_customers ".

Create a COM Component Project
Create a project, select COM/MTS component wizard, and click OK.
Define a name for the project "p_recordset_com"
Next, select the user object "uo_customer" to generate COM"
Set the interface attribute after the COM component is generated. The default attribute can be used here.
Then define the program ID of the component as "pb70.uocustomer ",
Select the DLL file name of the COM component and click "new" to generate "component server appid ",
Generate the "Type Library ID" and select the Pb resource file name and registration method.
Give the general information set by the user, and then choose to generate "to do list"
This completes a project for generating the COM component named "p_test_com ".

Compile the project and register Components
Open the generated project, select the corresponding PBL file and user object, and compile it.

Next we will create an ASP Webpage to call this Pb com
<Head> <title> Pb com </title> <Body>
<%
Set MERs = server. Createobject ("pb70.uo _ customers ")
Iflag = customers. uf_connect ()
Set rs = customers. uf_retrieve ()
%>
<Table>
<% Rs. movefirst
Do while not Rs. EOF
%>
<Tr>
<TD> <% = RS ("lname") %> </TD>
<TD> <% = RS ("Address") %> </TD>
<TD> <% = RS ("city") %> </TD>
</Tr>
<% Rs. movenext
Loop
Rs. Close
Customers. uf_disconnect ()
%>
</Table>
</Body>
Save as an ASP file

Finally, you can browse the ASP file in the browser.

Note: pb7.0 and pb8.0 are basically the same. You can practice them on your own.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.