云外归鸟工作室网站

标题: ODBC数据库连接库文件 [打印本页]

作者: 云外归鸟    时间: 2010-10-7 20:38
标题: ODBC数据库连接库文件
原作者:esir

NB ODBC 头文件(库文件)
支持连接到mssql,dBASE,MS Excel,MS FOX,MS Access, MySQL 和Text db(通过文本驱动)

"以ODBC方式连接到Access数据库测试.bas" 文件中 DBLink->Disconnect() 的位置有错。
原因是:销毁 记录集对象(即:DBRecord) 和 Statement对象(即:DBStmt) 后,才能关闭数据库链接(DBLink)、销毁关闭数据库链接对象。
[attach]92[/attach]

修正后的:

以ODBC方式连接到Access数据库测试.bas


'An example on how to use this library
'

#引用 仅一次 "Windows.bi"
#引用 仅一次 "crt.bi"
#引用 仅一次 "NBODBC.bi"


变量 DBLink 为 FBODBC.ODBCConnection 指针
变量 DBStmt 为 FBODBC.ODBCStmt 指针
变量 DBRecord 为 FBODBC.ODBCRecord 指针

DBLink = 创建 FBODBC.ODBCConnection

如果 DBLink-> MDBConnect(取运行目录()&"\Northwind.mdb","","",)= FALSE 则
?"Error connecting to MsAccess"
结束 如果

DBStmt = 创建 FBODBC.ODBCStmt(DBLink->DBC()) 'create new statement object , passing connection handle to the constructor

'querying the database...
DBStmt->Query("USE NorthWind")
DBStmt->Query("Select * From [Customers]")

'new Record object linked to the statement
DBRecord = 创建 FBODBC.ODBCRecord(DBStmt->m_hStmt)

变量 CustomerID 为 字符型 * 5

DBRecord->BindColumn(1,@CustomerID,5) 'bind first column to a buffer
DBStmt->FetchFirst() 'go to first row set
?CustomerID
DBStmt->FetchNext() ' go to next row set
?CustomerID
DBStmt->FetchLast() 'go to last row set
?CustomerID
DBStmt->FetchPrevious() 'go to previous row set
?CustomerID

变量 CompanyName 为 字符型 * 41
DBRecord->GetData(2,@CompanyName,41) 'Get data from the second column without bind it
?CompanyName

?DBStmt->GetChangedRowCount() 'get row count

  
销毁 DBRecord
销毁 DBStmt

DBLink->Disconnect()
销毁 DBLink

延时


作者: iokey    时间: 2010-10-11 20:02
好东西 下载学习一下




欢迎光临 云外归鸟工作室网站 (http://www.ywgn.net/) Powered by Discuz! X3