请问高手:VC怎么样调用Oracle(没有包的)存贮过程??能否给个实例?不胜感谢!!
解决方案 »
- 千千静听那种窗口总是最前功能如何实现的??而且发现进程任务窗口出来,它依然能保持最前。
- 急!!!调用DLL中的资源出错!
- 傻人问二个傻问题??
- 如何在DirectX上弹出窗口?就像金山游侠一样
- 对于任务兰上的窗口图标(不是系统托盘里的)右击鼠标弹出的菜单如何修改?
- 还有用API写程序的吗?我在用CreateWindow 建列表框时系统老是报错,死机,为什么
- CSDN 中有谁知道网络游戏“石器时代”外挂或封包程序的源代码?能发我一份吗?非常感谢!!!
- 一个关于new和delete的奇怪问题
- r调查一下杭州的工资水平[Visual C++]
- 我在WIN NT的服务控制管理器中,开始一个服务,当停止时......
- 请问VC初学者哪能个网站好
- 关于显示位图的问题?
CDatabase m_db;
m_db.OpenEx( _T("DSN=oracle" ),0);
CString strSql;
strSql.Format("过程的SQL")
m_db.ExecuteSQL(strSql);
m_db.Close();
各位大哥:能不能给个ADO的实例?我对ODBC不是太熟,呵呵!!
AfxOleInit();///初始化COM库
////////////连接数据库//////////////
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr))
{
hr=m_pConnection->Open("Provider=MSDAORA;Persist Security Info=FALSE;Data Source=DSN","UID","PWD",adModeUnknown);
}
AfxMessageBox("成功连接");
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
//CDialog::OnCancel();
//m_fConnected=FALSE;
return FALSE;
}
Create a dialog based vc application with a 'connect' button and another '
stored procedure' program.
On click on connect button to establish connection to the db write the code
below:
try
{
CoInitialize(NULL);
HRESULT hr = m_pConn.CreateInstance (__uuidof(Connection));
if(FAILED(hr)) _com_issue_error(hr); hr = m_pConn->Open(_bstr_t
("DSN=xxx;UID=xxx;PWD=xxx"),_bstr_t (""), _bstr_t (""),
adConnectUnspecified);
if(FAILED(hr)) _com_issue_error(hr); if (m_pConn->State == adStateOpen)
{
AfxMessageBox("Connected to the database");
} } // end try block
catch( _com_error &e )
{
m_pConn = NULL ;
_bstr_t bstrDescription (e.Description());
}2. on click of stored procedure to call the stored procedure with one input
and one output parameter.
long nResult=0,nEmpNo = 0;
_CommandPtr pCommand = NULL;
_ParameterPtr pName = NULL,pResult = NULL;
CString strQuery,strService;
_RecordsetPtr pRecordset;
//put some name as present in the db table here
_bstr_t v_bstrName="ccc"; VARIANT vGetValue;
vGetValue.vt = VT_BSTR | VT_I4 |VT_R8 | VT_NULL; try
{
HRESULT hr = pCommand.CreateInstance (__uuidof (Command));
if (FAILED(hr)) _com_issue_error(hr); pName = pCommand->CreateParameter("NAME", adBSTR,
adParamInput,30,v_bstrName);
pCommand->Parameters->Append(pName);
pResult= pCommand->CreateParameter("EMP_NO", adInteger,
adParamOutput,10);
pCommand->Parameters->Append(pResult); pCommand->ActiveConnection = m_pConn;
pCommand->CommandText = _bstr_t("EMP");
pCommand->CommandType = adCmdStoredProc;
nResult = pCommand->Execute(NULL,NULL,adCmdStoredProc );
if (nResult == 0)
{
AfxMessageBox("Failed to get the employee no.");
return ;
} vGetValue = pCommand->Parameters
->GetItem("EMP_NO")->GetValue();
if (vGetValue.vt !=VT_NULL)
{
nEmpNo = vGetValue.intVal;
AfxMessageBox("Success in getting the employee
no.");
} else
AfxMessageBox("Failed to get the employee no.");
}
catch ( _com_error &e )
{
_bstr_t bstrDescription (e.Description());
pCommand = NULL;
pRegNo = NULL;
pResult = NULL;
} //uninitialize all the smart pointers to null
pCommand = NULL;
pName = NULL;
pResult = NULL;Hope this helps.
CString m_strParam2=strdh22;
_CommandPtr m_pCommand;
_ParameterPtr m_param;
try
{
hr1 = m_pCommand.CreateInstance(__uuidof(Command));
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
catch(...)
{
AfxMessageBox("ADO建立命令失败!");
} m_param = m_pCommand->CreateParameter("FS_FILE",adVarChar, adParamInput,m_strParam1.GetLength()+1,_variant_t(m_strParam1));
m_pCommand->Parameters->Append(m_param);
m_param = m_pCommand->CreateParameter("D_N",adVarChar, adParamInput,m_strParam2.GetLength()+1,_variant_t(m_strParam2));
m_pCommand->Parameters->Append(m_param); m_pCommand->ActiveConnection = m_pConnection;
m_pCommand->CommandText = _bstr_t("OPEN_FILES");
m_pCommand->CommandType=adCmdStoredProc;
m_pCommand->Execute(NULL,NULL,adCmdStoredProc);
感谢!!