C++ 中使用数据库的问题

thoreau_zzy 2007-04-10 11:03:20
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")

#include <iostream.h>
#include <iomanip> //for setw()
#include <stdlib.h>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
CoInitialize(NULL);

try
{
_ConnectionPtr pConn("ADODB.Connection");
_bstr_t strConnect= "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=schedule";
pConn->Open(strConnect,"","",adModeUnknown);
_RecordsetPtr pRs("ADODB.Recordset");
pRs->Open("Select *From PLAN", _variant_t(pConn,true), adOpenStatic, adLockOptimistic, adCmdText);

while( !pRs->EndOfFile )
{
cout<<"sg: "<<_bstr_t(pRs->GetCollect("sg"))<<"\t";
string b = _bstr_t(pRs->GetCollect("sg"));
printf("b :\t",_bstr_t(pRs->GetCollect("sg")));
pRs->MoveNext();

}
pRs->Close();
pConn->Close();

}

catch(_com_error &e)
{
cout<<e.Error ()<<endl;

}
return 0;
}

SG的表为字符串
DT3482D1
DQ3440E1
DQ3440E1
DQ3440E1
DQ3440E1
AP1056E1
AP1056E1
AP1056E1
AP1056E1
AP1056E1
AP1056E1
AP1055E5
AP1055E5
现在想把它存到变量b中,不知道怎么存,
...全文
177 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
CathySun118 2007-04-10
  • 打赏
  • 举报
回复
b是什么类型?
thoreau_zzy 2007-04-10
  • 打赏
  • 举报
回复
b是什么类型都行
只要将sql中的字符串存起来就行
char string ...都是可以的
不知道怎么实现

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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