关于ADO组件自动生成的问题

aupttea 2003-11-11 09:16:30
我在写一个数据访问模块,如下:
遇到的问题是动态生成ADO组件的时候出了问题,求助!!
这个模块就是要实现无窗体的调用数据库组件,并访问数据库

#ifndef ACCESSREAD
#define ACCESSREAD
#include <vcl.h>
#include <string>
#include <ADODB.hpp>
#include <DB.hpp>
#include <ComObj.hpp>

using namespace std;

namespace AccessRead
{
int Read()
{
TADOConnection *ADOConnection1 = new TADOConnection(NULL);
//这个是可以的,也可以设定并连接上数据库
ADOConnection1->ConnectionString = "Driver= {Microsoft Access Driver (*.mdb)};DBQ=Information.mdb";

TADOTable *ADOTable1= new TADOTable(NULL);
//但这个就出错了,运行时说没有权限什么的。ADODataSet也不行

CoInitialize(NULL);
Variant AConnection = CreateOleObject("ADODB.Connection");
Variant ARecordSet = CreateOleObject ("ADODB.RecordSet");
//这两个建立的时候都可以,但后面我就不知如何做了
//AConnection.OleProcedure("Open", "");
CoUninitialize;
}
}
...全文
40 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
hswu 2003-11-12
  • 打赏
  • 举报
回复
程序没有问题,我也帮你试过,但如果你想在控制台程序中调用那是肯定不行的,nanyu(南郁) 说的没错你必须
Application->Initialize();
Application->Run();
的windows消息循环下调用
南郁 2003-11-12
  • 打赏
  • 举报
回复
不能没有Applicate 请套到里头去:
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
//Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------
aupttea 2003-11-12
  • 打赏
  • 举报
回复
是不是真的没有form就不能new出TADOTable啊?
但为什么能new出TADOConnection呢?
aupttea 2003-11-12
  • 打赏
  • 举报
回复
还是不行,我把全部代码都贴出来吧,如果解决了我再加200分。
我用的是Win2000_Pro_En BCB6_Enterprise
用bcb打开testAccessRead.cpp文件,自动生成工程。

//testAccessRead.cpp

#include "AccessRead.h"
#pragma package(smart_init)

using namespace std;

int main(int argc, char* argv[])
{
AccessRead::First();
return 0;
}

//AccessRead.h

#ifndef ACCESSREAD
#define ACCESSREAD
#include <vcl.h>
#include <string>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <ADODB.hpp>
#include <Db.hpp>

using namespace std;

namespace AccessRead
{
int First()
{
CoInitialize(NULL);
TADOTable *ADOTable1 = new TADOTable(NULL);
//就是上面这行运行的时候出了问题
CoUninitialize();
return 1;
}
}
#endif
pzoon 2003-11-12
  • 打赏
  • 举报
回复
TADOConnection *ADOConnection1 = new TADOConnection(Application->Owner);
aupttea 2003-11-12
  • 打赏
  • 举报
回复
我是希望别的程序调用我的模块的时候只包含这个 .h 文件就可以了
不想有什么窗体什么的。功能就是要读取数据库里的内容
swites 2003-11-12
  • 打赏
  • 举报
回复
gz1
aupttea 2003-11-12
  • 打赏
  • 举报
回复
TADOTable* myTable = new TADOTable(Application); 还是不行
ljianq 2003-11-12
  • 打赏
  • 举报
回复
你可以使用TDataModule,在里面操作数据就可以了。
cizi 2003-11-11
  • 打赏
  • 举报
回复
试试:
TADOTable* myTable = new TADOTable(Application);

aupttea 2003-11-11
  • 打赏
  • 举报
回复
或者是我的C++ Builder版本的问题么?
Question:

What is the cause of the error "Application is not licensed to use this feature"?

Answer:

This error occurs when you try to use components from one version of Delphi, such as Enterprise, with a different version that does not include those components, such as Standard. For example if you try to install the database components from the Enterprise version of Delphi into a Standard installation of Delphi.

Another possible cause is if you have the Standard version of Delphi installed on your machine and you install the Professional or Enterprise version without first uninstalling the Standard version. This error may also occur if you move a project from one version to another and keep the same compiled units (.dcu). It is best to delete the .dcu files and let them be recreated automatically.

Note: It is fine to have two different release versions of Delphi on your machine, such as Delphi 4 and Delphi 5, but not two versions of the same release such as Delphi 5 Standard and Delphi 5 Enterprise.

xu_xinyu 2003-11-11
  • 打赏
  • 举报
回复
用数据模块很好呀,为什么这么麻烦。
aupttea 2003-11-11
  • 打赏
  • 举报
回复
还是显示:
Application is not licensed to use this feature.

是因为我没有用form类么,应该有解决的办法吧
yangguo_god 2003-11-11
  • 打赏
  • 举报
回复
代码没问题,重建一个工程试试
aupttea 2003-11-11
  • 打赏
  • 举报
回复
up 一下,有人知道么?

1,178

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 数据库及相关技术
社区管理员
  • 数据库及相关技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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