这个问题我已经会了!请教一个新问题!
我写了两个com组件,ActionObj和DataObj。ActionObj封装业务逻辑,DataObj封装数据库操作。
DataObj定义一方法GetData返回类型是ADO原生对象_RecordSet。代码如下:
function TDataObj.GetData: Recordset;
begin
Result := dstTitles.Recordset as ADODB_TLB._Recordset ;
end;
ActionObj定义一方法GetComData返回类型也是ADO原生对象_RecordSet。代码如下:
function TActionObj.GetComData: ADODB_TLB._Recordset;
var
getrcddm : IDataObj ;
begin
getrcddm := CoDataObj.Create ; //创建DataObj对象
Result := getrcddm.GetData ; //返回DataObj对象所得到的RecordSet
end;
然后在ASP里调用代码如下:
Set NetTestASPObj = Server.CreateObject("GetData.ActionObj")
Set temp = NetTestASPObj.GetComData()
while not temp.eof
response.write "<tr>"
for i = 0 to temp.fields.count -1
response.write "<td align = center>"
response.write temp.fields(i).value
response.write "</td>"
next
response.write "</tr>"
temp.movenext
wend
浏览器提示:
ADODB.Recordset 错误 '800a0e78'
Operation is not allowed when the object is closed.
意思是数据集处于关闭状态。我不明白为什么?请问怎么解决?
如果前两行换成:
Set NetTestASPObj = Server.CreateObject("GetData.DataObj")
Set temp = NetTestASPObj.GetData()
即直接调用DataObj对象的GetData方法就行!
请各位大富翁指教哇!