vb应用程序访问sql server方法探讨(2)

发表于:2007-06-21来源:作者:点击数: 标签:
方法2.用odbc api编程 odbc(open database connectivity)的思想是访问异种 数据库 的一种可移植的方式。与数据资源对话的公用函数组装在一个称为驱动程序管理器(odbc.dll)的动态连接中。 应用程序调用驱动程序管理器中的函数,而驱动程序管理器反过来通过驱

   方法2.用odbc api编程

  odbc(open database connectivity)的思想是访问异种数据库的一种可移植的方式。与数据资源对话的公用函数组装在一个称为驱动程序管理器(odbc.dll)的动态连接中。

应用程序调用驱动程序管理器中的函数,而驱动程序管理器反过来通过驱动器反过来通来驱动器(sqlsrvr.dll)把它们送到服务器中。

  用odbc api编程,一般要用到以下一些函数。下面列出了常用的函数以及它们的功能。

  下面的代码使用上面一些函数先登录到一个服务器数据库,并为随后的工作设置了语句句柄。

global gihenv as long

global gihdb as long

global gihstmt as long

dim myresult as integer

dim myconnection as srting

dim mybuff as string*256

dim mybufflen as integer

if sqla||ocenv(gihenv)<>sql_suclearcase/" target="_blank" >ccess then

msgbox"a||ocation couldn’t happen!"

end if

if sql||occonnect(gihenv,gihdb)<>sql_success then

msgbox "sql server couldn’t connect!"

end if

myconnection="dsn=myserver;uid=|c|;pwd=;app=odbctest;ws|d=lcl;
database=sales"

myresult=sqldriverconnect(gihdb,test,form1.hwnd,myconnection
.len(myconnection),

mybuff,256,mybufflen,sql_driver_complete_requied)

myresult=sqla||ocstmt(gihds,gihstmt)

myresult=sqlfreestmt(gihstmt,sql_colse)

rssql="select*from customers where city="wuhan""

myresult=sqlexecdirect(gihstmt,rssql,len(rssql))

原文转自:http://www.ltesting.net