bin104959 2014-05-11 04:39
浏览 824

求大神帮忙,ado连接数据库sql server 2005,总是失败

#include
#include
#include
#include
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","ADOEOF")
int main()
{
if(!AfxOleInit())
{
AfxMessageBox("can't open the database!");
return 0;
}
_ConnectionPtr con;
_RecordsetPtr res;
con.CreateInstance("ADODB.Connection");
res.CreateInstance("ADODB.Recordset");
try{
CString connectstring="Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=jwglxt;Data Source=N36OUYVKXWZDR2G\SQLEXPRESS";
con->Open((_bstr_t)connectstring,"","",adModeUnknown);
}
catch(_com_error)
{
MessageBox(0,"make connection lost","connection lost",MB_OK);
return;
}
CString strsql="select * from student";
res.CreateInstance(_uuidof(Recordset));
res->Open((_bstr_t)strsql,con.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
printf("sno\t\tsname\t\tsage\t\tbir\n");
while(!res->BOF)
{
CString no;
CString name;
CString sex;
CString bir;
no=(CString)res->GetCollect("Sno").bstrVal;
name=(CString)res->GetCollect("Sname").bstrVal;
sex=(CString)res->GetCollect("Ssex").bstrVal;
bir=(CString)res->GetCollect("Sbir").bstrVal;
printf("%s\t%s\t%s\t%s\n",no,name,sex,bir);
res->MoveNext();
}
if(res!=NULL)
{
res->Close();
con->Close();
}
}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器