AppBuilder中进行直接ODBC API数据库调用访问的基本方法!
2008-09-25 19:27:00 来源:WEB开发网3、 取得数据库的名称:
如果已经打开了一个数据源,可以通过数据源来取得当前的数据库的名称;
CString SuperDatabase::GetDatabaseName()
{
ASSERT(m_hdbc != SQL_NULL_HDBC);
char szName[MAX_TNAME_LEN];
SWORD nResult;
SQLGetInfo(m_hdbc, SQL_DATABASE_NAME,
szName, MAX_TNAME_LEN, &nResult);
return szName;
}
三、 针对数据源的操作:
1、 增加数据源
BOOL SuperDatabase::CreateDSN(CString strDriver, CString strFileName,CString strDSN, CString strUserID, CString strPWD)
{
char szAttr[100+_MAX_PATH];
int j;
if (strDriver.IsEmpty())
strDriver = "Microsoft Access Driver (*.mdb)";
j = sprintf(szAttr,"DSN=%s",strDSN);
j++;
j = sprintf(szAttr+j,"DBQ=%s ",strFileName);
return SQLConfigDataSource(NULL,ODBC_ADD_DSN,strDriver,szAttr);
}
2、 删除数据源
void SuperDatabase::RemoveDSN(CString strDSN)
{
char szDSN[255];
sprintf(szDSN,"DSN=%s",strDSN);
BOOL bIsSuccess = SQLConfigDataSource(NULL,ODBC_REMOVE_DSN,"Microsoft Access Driver (*.mdb)",szDSN);
}
3、 取得系统已有得DSN
SWORD nDataSourceNameLength; //DSN str length
SWORD nSourceDescriptionLength; //Driver Description str length
char szSourceDescription[MAXBUFLEN+1]; //Driver Description string
SQLRETURN nResult; //Return Code
SWORD nDirection=SQL_FETCH_FIRST;
if ((nResult = SQLDataSources(m_henv, nDirection, (UCHAR *)((LPCTSTR)strDataSourceName), MAXBUFLEN, &nDataSourceNameLength, (UCHAR *)szSourceDescription, MAXBUFLEN, &nSourceDescriptionLength)) != SQL_NO_DATA && nResult != SQL_ERROR)
{
nDirection=SQL_FETCH_NEXT;
// szSourceDescription为DSN 的描述,可以在这里取来用;
}
Tags:AppBuilder 进行 直接
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接