vb应用程序访问sqlserver方法探讨(2)
来源:优易学  2011-12-10 19:53:49   【优易学:中国教育考试门户网】   资料下载   IT书店
  用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_success 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))

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训