//Create Recordset by executing the command pCmdChange->ActiveConnection = theApp.m_pConnection; //Create Recordset by executing the command m_pRecordset->CursorType=adOpenStatic; m_pRecordset->LockType=adLockPessimistic; m_pRecordset = pCmdChange->Execute(NULL,NULL,adCmdStoredProc); //m_pRecordset->Open("{CALL (?{20})}",_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenStatic,adLockPessimistic,adCmdStoredProc); /**/ } catch (_com_error e) { AfxMessageBox(e.Description()); return FALSE; }这样就可以得到pkgtest.get返回的记录集
delphi:SQL> select * from aa; ID NAME ---------- -------- 1 猪八戒 2 孙悟空 CREATE OR REPLACE PACKAGE pkg_test AS TYPE myrctype IS REF CURSOR; END pkg_test; / create or replace PROCEDURE get(p_rc OUT pkg_test.myrctype) IS sqlstr VARCHAR2 (50); BEGIN sqlstr:='select * from aa'; OPEN p_rc FOR sqlstr; END get; / 在窗体上放一个ADOStoredproc 设置 procedurename=get prepared = true active = true 还有 connectstring 代码如下,好运! procedure TForm1.Button1Click(Sender: TObject); begin adostoredproc1.close; adostoredproc1.open; label1.caption:= ADOStoredProc1.fields[1].asstring; while not adostoredproc1.eof do begin label2.caption:= ADOStoredProc1.fields[1].asstring; adostoredproc1.Next; end; end;
m_pConnection.CreateInstance("ADODB.Connection");
/******************连接数据库********************/
try
{
m_pConnection->ConnectionTimeout = 8;
//连接SQL SERVER
//m_pConnection->Open("Driver=SQL Server;Database=test;Server=127.0.0.1;UID=sa;PWD=;","","",adModeUnknown);
//连接ACCESS2000
//m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=userinfo.mdb","","",adModeUnknown);
//连接到oracleMSDAORA oraoledb.oracle
m_pConnection->Open("Provider=oraoledb.oracle;Data Source=ep;User ID=zongdui;Password=zongdui;PLSQLRSet=1","","",adModeUnknown); }
catch(_com_error e)///捕捉异常
{
AfxMessageBox("数据库连接失败!");
return FALSE;
}
/**********************************************/上面是连接数据库,PLSQLRSet=1这个一定要有。 m_bNewUser = FALSE;
m_pRecordset.CreateInstance("ADODB.Recordset");
try
{
//m_pRecordset->Open("SELECT name as username,old,photo as photo1 FROM test",_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenStatic,adLockPessimistic,adCmdText);
_CommandPtr pCmdChange = NULL;
// _ParameterPtr pprmByRoyalty = NULL; pCmdChange.CreateInstance(__uuidof(Command));
pCmdChange->CommandType = adCmdStoredProc;
pCmdChange->CommandText = "pkg_test.get";
//Define Integer/variant.
// pprmByRoyalty.CreateInstance(__uuidof(Parameter));
// VARIANT vtRoyalty;
// vtRoyalty.vt = VT_I2;
// vtRoyalty.iVal = 20;
// pprmByRoyalty = pCmdChange->CreateParameter("param1",adInteger,adParamInput,sizeof(int),vtRoyalty);
// pCmdChange->Parameters->Append(pprmByRoyalty); // pprmByRoyalty->Value = vtRoyalty;
//Create Recordset by executing the command
pCmdChange->ActiveConnection = theApp.m_pConnection; //Create Recordset by executing the command
m_pRecordset->CursorType=adOpenStatic;
m_pRecordset->LockType=adLockPessimistic;
m_pRecordset = pCmdChange->Execute(NULL,NULL,adCmdStoredProc);
//m_pRecordset->Open("{CALL (?{20})}",_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenStatic,adLockPessimistic,adCmdStoredProc);
/**/
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
return FALSE;
}这样就可以得到pkgtest.get返回的记录集
---------- --------
1 猪八戒
2 孙悟空
CREATE OR REPLACE PACKAGE pkg_test
AS
TYPE myrctype IS REF CURSOR;
END pkg_test;
/ create or replace PROCEDURE get(p_rc OUT pkg_test.myrctype)
IS
sqlstr VARCHAR2 (50);
BEGIN
sqlstr:='select * from aa';
OPEN p_rc FOR sqlstr;
END get;
/ 在窗体上放一个ADOStoredproc
设置 procedurename=get
prepared = true
active = true
还有 connectstring
代码如下,好运! procedure TForm1.Button1Click(Sender: TObject);
begin
adostoredproc1.close;
adostoredproc1.open;
label1.caption:= ADOStoredProc1.fields[1].asstring;
while not adostoredproc1.eof do
begin
label2.caption:= ADOStoredProc1.fields[1].asstring;
adostoredproc1.Next;
end;
end;