'这个简单
'引用 ODBC Driver & Data Source Name Functions
Dim x As New ODBCTool.Dsn
x.CreateDSN ....
'引用 ODBC Driver & Data Source Name Functions
Dim x As New ODBCTool.Dsn
x.CreateDSN ....
解决方案 »
- 如何捕捉 ListView 滚动条事件
- 请用过海康DS_40xxHC视频卡SDK开发过软件的请进来看看
- 【问】如何显示多边形的照片?
- 团结就是力量 我不认输 进者给分 免费放送经典的娱乐搞笑 各位兄弟姐妹 你们辛苦了 工作之余 记得休息哦
- update,delete,insert into 出错!!!
- 怎么比较字符才不区分大小写
- vb小问题 round
- 关于禁止截屏的代码?
- 求: 把一个字符串里面的所有全角字符变成半角字符的函数
- 把word文件保存到access/sqlserver某字段中,谁有更好的办法?
- 请教各位,在SQL Server 数据库中,能不能给数据库增加自定义属性
- 我在窗体中加了一个ado数据控件,该控件的recordsource="select * from tblCity where ProvinceID=" & lngID 数据源不为空。为什么ado数
===========================================================
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
RDO为:rdoRegisterDataSource具体使用方法可参见MSDN
给个简单的例子
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 PointerPrivate Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
(ByVal hwndParent As Long, ByVal fRequest As Long, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long
Named Pripes
Public Sub CreateDSN(sDSN As String)
Dim nRet As Long
Dim sDriver As String
Dim sAttributes As String
sDriver = "Oracle73 Ver 2.5"
sAttributes = "Server=Oracle8" & Chr$(0)
sAttributes = sAttributes & "DESCRIPTION=" & sDSN & Chr$(0)
'sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)
sAttributes = sAttributes & "DATABASE=DBFinance" & Chr$(0)
sAttributes = sAttributes & "Userid=Scott" & Chr$(0)
'sAttributes = sAttributes & "PWD=myPassword" & Chr$(0)
DBEngine.RegisterDatabase sDSN, sDriver, True, sAttributes '爹
'nRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, sDriver, sAttributes) '爹
End SubPublic Sub DeleteDSN(sDSN As String)
Dim nRet As Long
Dim sDriver As String
Dim sAttributes As String
sDriver = "Oracle73 Ver 2.5"
sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)
nRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, sDriver, sAttributes)
End Sub