如何在pb中建立COM組件,並在asp中調用並返回結果集?

來源:互聯網
上載者:User
啟動pb7.0,建立一個不可視的使用者物件"uo_customer",建立"object",選擇"custom  class"
類型,點擊"ok"。
在新建立的使用者物件中編寫如下程式:
1.聲明執行個體變數"instance  variables",對於com中不支援的類型,請聲明為protected類型。protected:
        datastore  ds_datastore
2.建立三個成員函數:
int  uf_connect()//用於連結資料庫與建立datastore對象。
代碼:
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()//用於斷開資料庫連結和釋放datastore對象。
if  isvalid(ds_datastore)  then  destroy  ds_datastore
disconnect  using  sqlca;

resultset  uf_retrieve()//讀取客戶資訊
resultset  lrs_customers
ds_datastore.dataobject="d_customer"
ds_datastore.retrieve()
ds_datastore.generateresultset(lrs_customers)//產生結果集
return  lrs_customers//返回結果集
最後,儲存改對象為"uo_customers"。

製作一個com組件的工程
建立"project",選擇"Com/mts  component  wizard",確定。
給工程定義一個名字"p_recordset_com"
接下來,選擇要產生com的使用者物件"uo_customer"
設定產生com組件後的介面屬性,這裡可以使用預設。
然後自己定義組件的program  id為"pb70.uocustomer",
然後選擇該com組件的dll檔案名稱,單擊"new",產生"component  server  appid",
同樣產生"type  library  id",最後,選擇pb資源檔名,以及註冊方式,之後,系統會
給出使用者佈建的大致資訊,然後選擇產生"to  do  list"
這樣就完成一個產生com組件的工程,名為"p_test_com"。

編譯工程並註冊組件
開啟已經產生的工程,選擇相應的pbl檔案及使用者物件,編譯就可以了

下面我們建立asp網頁來調用這個pb  com
<head><title>pb  com</title></head>
<body>
<%
set  customers=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>
儲存成asp檔案

最後,在瀏覽器中就可以瀏覽這個asp檔案了

說明:pb7.0和pb8.0基本上差不多,讀者可以自己實踐。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.