[OLE DB] 怎么用IRowChange::Insert插入数据啊?

Codavid 2005-10-15 10:22:16
我定义的对象入下:
CDataSource ds;
CSession ss;
CCommand<CDynamicAccessor> rs;

我用rs.open(...)成功打开了数据库,并设置了DBPROP_UPDATABILITY
可我不知道怎么插入数据, 我调用rs.Insert()返回S_OK,但调用rs.Update时就出错,这是为什么??
...全文
116 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Codavid 2005-10-17
  • 打赏
  • 举报
回复
不是吧....没人知道?? 急啊~~~
Codavid 2005-10-16
  • 打赏
  • 举报
回复
........终于有人回了...我是在VS.NET下写的,你帮我看一下吧,谢谢!! :)

CDataSource ds;
CSession ss;
CCommand<CDynamicAccessor> rs;

CoInitialize(NULL);
USES_CONVERSION;

ds.Open();
BSTR buff;
ds.GetInitializationString(&buff, true);

cout<<OLE2T(buff)<<endl;;
SysFreeString(buff);
ss.Open(ds);

CDBPropSet* DBPropSet = new CDBPropSet(DBPROPSET_ROWSET);
DBPropSet->AddProperty(DBPROP_IRowsetUpdate, true);
DBPropSet->AddProperty(DBPROP_UPDATABILITY,
DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_DELETE | DBPROPVAL_UP_INSERT);
DBPropSet->AddProperty(DBPROP_CANSCROLLBACKWARDS, true);
DBPropSet->AddProperty(DBPROP_CANFETCHBACKWARDS, true);

rs.Open(ss, "SELECT 姓名 FROM oletest", (DBPROPSET*)DBPropSet);

for(DBORDINAL col = 1; col <= rs.GetColumnCount(); col++)
{
LPTSTR szBuff = OLE2T(rs.GetColumnName( col ));
cout<<szBuff<<'\t';
}
cout<<endl;

HRESULT hr = rs.MoveNext();
while(SUCCEEDED(hr) && hr != DB_S_ENDOFROWSET)
{
DBSTATUS DBStatus;
DBTYPE DBType;

rs.GetStatus( 1, &DBStatus);
rs.GetColumnType(1, &DBType);

if(FAILED(DBStatus))
cout<<"FAILED";
else if( DBStatus == DBSTATUS_S_ISNULL )
cout<<"<<NULL>>";
else if( DBType == DBTYPE_WSTR || DBType == DBTYPE_STR)
{
LPWSTR buff = (LPWSTR)rs.GetValue(1);
CString pszData = CString(buff);
cout<<pszData;

}
cout<<endl;

hr = rs.MoveNext();
}
LPWSTR pwszName = (LPWSTR)rs.GetValue(1);
wcscpy(pwszName, L"uu");
//rs.SetLength(1,2);
rs.SetStatus(1, DBSTATUS_S_OK);
rs.Insert();
rs.Update();
///////////在这里就出错了,下面的就不用看了/////////////
rs.MoveFirst();

LPWSTR pwszData = (LPWSTR)rs.GetValue(1);
wcscpy(pwszData, L"hhh");
DBCOUNTITEM rt = 0;
rs.SetData();
rs.Update();
cout<<rt<<endl;

rs.Close();
ss.Close();
ds.Close();
CoUninitialize();

帮帮我啊...谢谢
Codavid 2005-10-16
  • 打赏
  • 举报
回复
照上面的代码,调用rs.Update()的错误是DB_E_ROWSNOTRELEASED(列没有释放)
如果在它的前面加了rs.ReleaseRows() rs.Update()的错误是DB_E_ERRORSOCCURED(发生错误)

...晕啊!!!~~~ 有没有人知道这个怎么弄啊?
threenewbee 2005-10-15
  • 打赏
  • 举报
回复
什么错误?
我可以啊。

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧