惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
J
Java Code Geeks
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
MyScale Blog
MyScale Blog
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
N
Netflix TechBlog - Medium
MongoDB | Blog
MongoDB | Blog
I
InfoQ
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Help Net Security

博客园 - Niyo Wong

用于主题检测的临时日志(f89708b9-f679-4391-af74-c92d9138aed4 - 3bfe001a-32de-4114-a6b4-4005b770f6d7) 测试用Word 2007发布博客 【转】ASP.NET Page事件的执行顺序 ASP.NET页面请求过程 JSP 执行过程 SQL Server 2005 错误处理笔记 .Net内存分配笔记 UML入门 与健康有约——送给每一个关心自己身体的人 .net 如何设置和检索特性信息(attribute) T-SQL编程基础-游标 .net中的4种事务总结 T-SQL编程基础-基本语法 Javascript调用服务器端事件 模式窗口页面不更新的问题 ASP.NET菜鸟进阶-Response.Write与RegisterXXX ASP.NET菜鸟进阶-页面间参数传递 差点把这好地儿给荒废了 我们的生活离不开笑
VC++(MFC)数据库程序——入门
Niyo Wong · 2007-12-18 · via 博客园 - Niyo Wong

刚开始学习VC,凭以往经验,先从数据库程序开始入门是最好的。简单,容易上手。在网上下载了几个例子,照着描红起来。几天下来自己也弄了几个例子。现在把自己的一点心得记下来:
1.在StdAfx.h中引入ado控件
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","rsEOF")
2.用AfxOleInit()初始化Com
if(!AfxOleInit())
 {
  AfxMessageBox("Ole Initialization failed!");
  return false;
 }
3._ConnectionPtr,_CommandPtr,_RecordSetPtr的使用
//define
_ConnectionPtr pConn;
_CommandPtr pCmd;
_RecordsetPtr pRst;
 pConn.CreateInstance(__uuidof(Connection));//
 pCmd.CreateInstance((__uuidof(Command)));

 pRst.CreateInstance((__uuidof(Recordset)));
//connection string
pConn->ConnectionString="Provider=SQLOLEDB.1;Password=;Persist Security Info=True;User ID=sa;Initial Catalog=pubs";
//open connection
try
{
    pConn->Open("","","",adModeUnknown);
}
catch(_com_error e)
{
    AfxMessageBox(e.ErrorMessage());
}
//execute sql, fill recordset
try
{
 pRst=pConn->Execute("select * from authors",NULL,adCmdText);  
}
catch(_com_error e)
{
 AfxMessageBox(e.ErrorMessage());
 return ;
}
//display data
try
{
  while(!pRst->rsEOF)
  {
    ((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("au_lname"));
    pRst->MoveNext();
  }
}catch(_com_error *e)
{
 AfxMessageBox(e->ErrorMessage());
}