7,713
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<utility>
#include <windows.h>
#include "sql.h"
#include "sqltypes.h"
#include "sqlext.h"
#include "ODBCINST.h"
using namespace std;
BOOL CreateDSN()
{
char *szDesc;
int mlen;
szDesc = new char[256];
sprintf(szDesc, "DSN=%s:DECRIPTION=TOC support source:\
DBQ=%s:FIL=MicrosoftAccess:\
DEFAULTDIR=D:\\Database::", "ODBCDemo1", "D:\\Database\\book.mdb");
mlen = strlen(szDesc);
for(int i=0; i<mlen; i++)
{
if(szDesc[i]==':')
szDesc[i] = '\0';
}
if(!SQLConfigDataSource(NULL,ODBC_ADD_DSN, "Microsoft Access Driver(*.mdb)\0", (LPCSTR)szDesc))
{
return FALSE;
}
else
{
return TRUE;
}
}
int main()
{
/*
HENV henv;
RETCODE rcode, m_retcode, retcode;
rcode = ::SQLAllocEnv(SQL_HANDLE_ENV,SQL_NULL,&henv);
if(rcode==SQL_SUCCESS)
{
cout << "success create henv" << endl;
}
HDBC hdbc;
retcode = ::SQLAllocConnect(henv,&hdbc);
if(retcode==SQL_SUCCESS)
{
cout << "success create hdbc" << endl;
}
m_retcode = ::SQLConnect(hdbc, (PUCHAR)psz)*/
return 0;
}