补充:因为在ADO中DBF数据库只能用ODBC连接,所以现在想根据DBF库路径用VB创建一个DBF库的DSN,最好给出代码。谢谢。
解决方案 »
- vba关于事务的问题
- Textbox向下移动
- 谁能告诉我 rs.cursorType=adopen.keyset 和rs.LOckType=adLockOptimistic 语句个是什么意思具体点
- 请问CurrentX = I: CurrentY = 7: Line -(I, 0)这句话中":"是什么意思?
- 如何防止拈贴到文本框之前,进行判断?
- 关于锁定鼠标的问题!!急急急!!!
- 在vb中插入其他高级语言
- 如何使用VB在Access97的数据库中建立一个表?
- 当执行rs.open后,执行rs.close出错!
- 关于API制作菜单的问题!(高手必看)
- 如何用SQL Enterprise Manager 运行pubs数据库中的Accounts.sql脚本
- 如何获得某文件的路径!!!????
建立ODBC,利用ODBC api添加dns方法.
'Constant Declaration
Private Const ODBC_ADD_DSN = 1 ' Add data source
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
Private Const ODBC_REMOVE_DSN = 3 ' Remove data source
Private Const vbAPINull As Long = 0& ' NULL Pointer
Private Declare Function SQLAllocEnv Lib "odbc32.dll" (phenv&) As Integer
'Function Declare
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL"(ByVal hwndParent As Long, ByVal fRequest As Long,ByVal lpszDriver As String, ByVal lpszAttributes As String)As Long
Option ExplicitPrivate Sub Command1_Click()
Dim intRet As Long
Dim strDriver As String
Dim strAttributes As String
strDriver = "Microsoft Access Driver (*.mdb)"
'Set the attributes delimited by null.
'See driver documentation for a complete list of attributes.
strAttributes = "DSN=DSN_TEMP" & Chr$(0)
'To show dialog, use Form1.Hwnd instead of vbAPINull.
intRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN,
strDriver, strAttributes)
If intRet Then
MsgBox "DSN Deleted"
Else
MsgBox "Delete Failed"
End IfEnd SubPrivate Sub Command2_Click()
Dim intRet As Long
Dim strDriver As String
Dim strAttributes As String
Dim rc As Integer 'ODBC 函 数 的 返 回 码
Dim henv As Long 'ODBC 环 境 句 柄
rc = SQLAllocEnv(henv) ' 获 取ODBC 环 境 句 柄
strDriver = "Microsoft Access Driver (*.mdb)"
strAttributes = "SERVER=SomeServer" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)
strAttributes = strAttributes & "DSN=DSN_TEMP" & Chr$(0)
strAttributes = strAttributes & "DBQ=d:\pdzl.mdb" & Chr$(0)
strAttributes = strAttributes & "UID=admin" & Chr$(0)
strAttributes = strAttributes & "PWD=" & Chr$(0)
'To show dialog, use Form1.Hwnd instead of vbAPINull.
intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
strDriver, strAttributes)
If intRet Then
MsgBox "DSN Created"
Else
MsgBox "Create Failed"
End If
End Sub
Option Explicit
Private Declare Function SQLDataSources Lib "ODBC32.DLL" (ByVal henv&, ByVal fDirection%, ByVal szDSN$, ByVal cbDSNMax%, pcbDSN%, ByVal szDescription$, ByVal cbDescriptionMax%, pcbDescription%) As Integer
Private Declare Function SQLAllocEnv% Lib "ODBC32.DLL" (env&)
Const SQL_SUCCESS As Long = 0
Const SQL_FETCH_NEXT As Long = 1
Public shujupath As String
'用代码配置mdb数据库
Sub info()
Dim strdescription, strattributes
On Error GoTo aa
Dim lg As Long
Dim de As DBEngine
Set de = New DBEngine
strdescription = "试验数据源" '描述
Dim aa As String
aa = appstr & "db\db.mdb"
strattributes = "dbq=" & aa & _
vbCr & "description=" & strdescription & _
vbCr & "Fil=ms access" & _
vbCr & "uid=" & "password="
de.RegisterDatabase "shuju", "microsoft access driver (*.mdb)", True, strattributes
Exit Sub
aa:
MsgBox "调试失败"
End Sub