CSDN博客

img B2China

在VC中如何实现对存储过程的循环调用?

发表于2004/7/14 8:57:00  1325人阅读

// 声明对象
_ConnectionPtr  Conn1;
_CommandPtr Cmd1;
_RecordsetPtr  Rs1;
_ParameterPtr  param;

// 初始化

 ::CoInitialize(NULL);
param.CreateInstance("ADODB.Parameter");

HRESULT hr = Cmd1.CreateInstance(__uuidof(Command));
if(FAILED(hr))
{
AfxMessageBox("_CommandPtr初始化失败");
 return ;
}

CString strSQLStore;  // 组织sql语句
strSQLStore ="update "+strTableName   +" set GWERRORCODE=93 where USERNUMBER = ParamUserNumber; ";

// 实现在程序中创建存储过程
_bstr_t bstrCreate( 
L"create  or replace procedure  UpdateDB ( ParamUserNumber  varchar2)   "
L" as "
L" begin "
+strSQLStore+
L" commit; end ;");
_bstr_t  bstrSP(L"UpdateDB" );
 m_pCon->Execute(bstrCreate,NULL,adCmdText);
 //m_pCon->Execute(bstrCreate,&RecordsetAffected,amdText);

// 关联连接,m_pCon是_ConnectionPtr 类型的已有的活动连接
Cmd1->ActiveConnection =  m_pCon;
Cmd1->CommandTex  =  bstrSP;
Cmd1->CommandType = adCmdStoredProc;

// 存储过程入口参数的初始化
_variant_t varTemp;
CString test ;
param->Name="ParamUserNumber";
param->Type=adChar;
param->Size=20;
param->Direction=adParamInput;
int y = Cmd1->Parameters->Count;
Cmd1->Parameters->Append(param);
Cmd1->Parameters->Refresh();

// 循环执行存储过程
CString strSQL;
while(LineNo){
 // 刷新界面,处理其它请求

MSG msg;
while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
if(m_bExit)
{
return;
}
if(m_bStop)
{
// 如果检测到有暂停的消息

MSG msg;
while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
Sleep(1);
if(IDYES == MessageBox("是否暂停执行存储过程?"提示",MB_YESNO+MB_ICONQUESTION))
return;
}

 // 每一行的信息,代表了要查询的入口参数的值

LineInfo = LineArray[LineNo];

LineInfo.number = L"'"
+LineInfo.number+
L"'"; // 参数格式化

 

// 参数赋值
//Cmd1->GetPrepared();
test = LineInfo.number;
varTemp.vt = VT_BSTR;
varTemp.bstrVal = (_bstr_t)test;
Cmd1->Parameters->Item[(short)0]->Value  = varTemp.bstrVal;

 // 执行存储过程
Cmd1->Execute(NULL, NULL, adCmdStoredProc);

try
{
m_pRs->Open(strSQL.AllocSysString(),m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);?
}

LineNo++;
m_ProgressCtrl.SetPos(LineNo);
}

0 0

相关博文

我的热门文章

img
取 消
img