在使用fileds的getname函数时出现了异常,如下
res = 1
数据库操作失败
Error
Code = 800a0cc1
Code meaning = Unknown error 0x800A0CC1
Source = ADODB.Fields
Description = 在对应所需名称或序数的集合中,未找到项目。
end
请按任意键继续. . .
不知道是怎么回事 使用的语句是select count(*) from demo_tab
出错代码是m_pRecordset->GetFields()->GetItem(0)->GetName()语句是执行成功的 count(*)的值也能正确获取 (详细代码见沙发)
res = 1
数据库操作失败
Error
Code = 800a0cc1
Code meaning = Unknown error 0x800A0CC1
Source = ADODB.Fields
Description = 在对应所需名称或序数的集合中,未找到项目。
end
请按任意键继续. . .
不知道是怎么回事 使用的语句是select count(*) from demo_tab
出错代码是m_pRecordset->GetFields()->GetItem(0)->GetName()语句是执行成功的 count(*)的值也能正确获取 (详细代码见沙发)
解决方案 »
- 搞计算机的除了英语,想学第二门外语
- 请教如何使对话框充满视图区域
- 使用api函数的TextOut()进行打印的时候,怎样控制起点不随打印机变化而变化
- 学了VC数据库编程,想做个小的数据库管理系统,没头绪,郁闷!进来的人都有分!
- 求电子版本 Visual C++6.0实用教程
- 关于button
- 做一个类似防火墙的程序,放在服务器上用,可以过滤局域网内其它机器上网的数据,可有简单的方法(若不做驱动);有好的建议也可
- 关于PreCreateWindow(CREATESTRUCT& cs)的使用
- 急!!关于音频压缩的问题
- 用VC++6 写了一个发HTML邮件程序,但是接收到邮件时候出现编码错误。
- 在vista下调用vc6.0的编译器cl.exe报错了(有图)
- 如何封装用MFC编写网络通信客户端
// test_ado.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")void PrintComError(const _com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description()); // Print COM errors.
printf("Error\n");
printf("\tCode = %08lx\n", e.Error());
printf("\tCode meaning = %s\n", e.ErrorMessage());
printf("\tSource = %s\n", (LPCSTR) bstrSource);
printf("\tDescription = %s\n", (LPCSTR) bstrDescription);
}
int main(int argc, _TCHAR* argv[])
{ CoInitialize(NULL);
HRESULT hr;
_ConnectionPtr m_pConnection; try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr))
{
hr = m_pConnection->Open("Provider=MSDAORA.1;Data Source=demo_tab;", "demo_tab", "demo_tab", adModeUnknown);///连接数据库
///上面一句中连接字串中的Provider是针对ACCESS2000环境的,对于ACCESS97,需要改为:Provider=Microsoft.Jet.OLEDB.3.51;
_variant_t RecordsAffected;
///执行SQL命令:CREATE TABLE创建表格users,users包含四个字段:整形ID,字符串username,整形old,日期型birthday
//m_pConnection->Execute("CREATE TABLE users(ID INTEGER,username TEXT,old INTEGER,birthday DATETIME)",&RecordsAffected,adCmdText);
///往表格里面添加记录
//m_pConnection->Execute("INSERT INTO users(ID,username,old,birthday) VALUES (1, 'Washington',25,'1970/1/1')",&RecordsAffected,adCmdText);
///将所有记录old字段的值加一
//m_pConnection->Execute("UPDATE users SET old = old+1",&RecordsAffected,adCmdText);
///执行SQL统计命令得到包含记录条数的记录集
_RecordsetPtr m_pRecordset;
m_pRecordset = m_pConnection->Execute("select count(*) from demo_tab", &RecordsAffected, adCmdText);
_variant_t vIndex = (long) 0;
_variant_t vCount = m_pRecordset->GetCollect(vIndex);///取得第一个字段的值放入vCount变量
printf("res = %ld\n", vCount.lVal);
//m_pRecordset->GetFields()->GetItem(0)->GetNumericScale();
printf("%s = %d\n", m_pRecordset->GetFields()->GetItem(0)->GetName() , vCount.lVal); m_pRecordset->Close();///关闭记录集
m_pRecordset->Release();
m_pConnection->Close();
m_pConnection->Release(); }
}
catch(const _com_error &e)///捕捉异常
{
printf("数据库操作失败\n");
PrintComError(e);
} printf("end\n");
CoUninitialize();
return 0;
}
http://download.csdn.net/source/335237