vc ado 更新一个表的id字段

来源:互联网 发布:spss软件使用方法文字 编辑:程序博客网 时间:2024/06/05 16:04
int CImpexpData::UpdateID()
{
_ConnectionPtr m_pConnection;
HRESULT hr = m_pConnection.CreateInstance(__uuidof(Connection));
CString sConstring;
CString sUser ="oa";
CString sPassword ="oa";
sConstring.Format("Provider=OraOLEDB.Oracle;\
Persist Security Info=false;\
User ID=%s;Password=%s;\
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=%s)(PORT=%s)))(CONNECT_DATA=(SERVICE_NAME=%s)))",
"oa","oa","192.168.1.135" ,"1521","orcl");
if (hr==S_OK)
{
m_pConnection->CommandTimeout= 10;
hr = m_pConnection->Open((_bstr_t)sConstring,(_bstr_t)sUser,(_bstr_t)sPassword,adConnectUnspecified);
if (hr== S_FALSE)
{
return NULL;
}
}
CString sql;
sql.Format(_T("select * from oa2_user"));

_variant_t vName,vID, vOrder, vNote;
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open(_bstr_t(sql),_variant_t((IDispatch*)m_pConnection,true), adOpenDynamic, adLockOptimistic, adCmdText);
int i=0;
while(!m_pRecordset->EndOfFile)
{
long id =m_pRecordset->GetCollect("ID");
m_pRecordset->PutCollect("ID", id+1);//这里id+1换成i++就是重新从1排序,,,
m_pRecordset->Update();
m_pRecordset->MoveNext();

}

m_pRecordset->Close();
return 1;
}
0 0
原创粉丝点击