日期:2014-05-18  浏览次数:20397 次

ado连接sql2005的读取问题
开发环境是vc6.0加sql2005
代码:
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=bingle;Data Source=(local)";
pConn->Open("","","",adConnectUnspecified);
pRst = pConn->Execute("select * from myTable1",NULL,adCmdText);
while(!pRst->EndOfFile)
{
wchar_t* str=(wchar_t *)(_bstr_t)pRst->GetCollect("bingle2");

printf("%s\n",str);
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
红色标注的地方不知道怎么转化。bingle2是一个varchar(50)的column,数据是test1,haha1
但是读出的结果确实数据的首字母,也就是t和h。我不知道为什么会这样,纠结老长时间了,望坛友多帮忙!

------解决方案--------------------
探讨
建议去VC版问问

------解决方案--------------------
是不是指针取址的问题,去问问相关人士