- 增加库文件 #pragma comment(lib, "odbccp32.lib ")
- 包含头文件 #include <odbcinst.h>
- 调用函数
::SQLConfigDataSource(NULL,ODBC_ADD_DSN,
"Oracle in OraDb10g_home1",
"DSN=mT\0"
"Description=DATASOURCE\0"
"Server=his\0"
))
示例:
#include <vcl.h>
#pragma hdrstop
#include <odbcinst.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#pragma comment(lib, "odbccp32.lib ")
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//-------www.cnblogs.com/zhangdongsheng--------------------------------------------------------------------
void __fastcall TForm1::btn_1Click(TObject *Sender)
{
if(::SQLConfigDataSource(NULL,ODBC_ADD_DSN,
"Oracle in OraDb10g_home1",
"DSN=mT\0"
"Description=DATASOURCE\0"
"Server=his\0"
))
/* if(::SQLConfigDataSource(NULL,ODBC_ADD_DSN, "Microsoft Excel Driver (*.xls)",
"DSN=New Excel Data Source\0"
"Description=New Excel Data Source\0"
))*/
ShowMessage("成功");
else
ShowMessage("失败");
}