直接使用ODBC API操作数据库前提

使用ODBC API之前要用到的头文件和LIB库
  #include "sql.h" // This is the the main include for ODBC Core functions.
  #include "sqlext.h" // This is the include for applications using the Microsoft SQL Extensions
  #include "sqltypes.h" // This file defines the types used in ODBC
  #include "sqlucode.h" // This is the the unicode include for ODBC Core functions
  #include "odbcss.h" // This is the application include file for the SQL Server driver specific defines.
  #pragma coment(lib, "odbc32.lib")

这些头文件在vc安装目录的INCLUDE里面都有。

但是如果就这样直接使用这些头文件,在编译的时候会出现如下错误:
 error   C2146:   syntax   error   :   missing   ';'   before   identifier   'SQLHWND'   

fatal   error   C1004:   unexpected   end   of   file   found

解决办法:在最前面加上#inlcude <windows.h>  因为sql.h中引用了windows.h的一些定义方法

这样,就可以使用ODBC API直接进行数据库操作了。而不使用MFC的相关类。


动态加载数据源:

通过ODBC API加载:Windows系统子目录下的动态链接库Odbcinst.dll提供了一个可以动态增加、修改和删除数据源的函数SQLConfigDataSource,由于VC的默认库文件中不包含此函数,因此使用前需将Odbcinst.h文件包含在工程的头文件中,在工程的setting属性框Link页的Object/library module编辑框中增加Odbc32.lib,同时保证系统目录system32下有文件Odbccp32.dll。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值