是否有现成的比较完整的程序?谢谢!
解决方案 »
- 懂midi 的进来看一下
- vb+sql2000怎么连接啊?
- 请教一个用vb连接VF中的.DBF数据库问题.
- 请指点:在CommonDialog控件的showopen方法中怎么样遍历同一目录下的同类文件?
- 请问form 与 picturebox 的Cls方法用了哪些Api函数? 我想用Api函数代替cls方法。
- 发布一个图表控件,散分。
- 请问怎样得到 msflexgrid 的某个单元格的 top ,left , width , height ????
- 关于ListView特怪的情况,寻求高手解答
- 抢分啦,28日18:00结账(每日9:00-18:00在线)
- 你能帮助一只迷惑的猪吗???
- 如何用sendMessage向一个按钮发消息??
- 如何用sendMessage向一个按钮发消息??
http://www.stvb.com/shownews.asp?NewsID=1183
Const ODBC_ADD_SYS_DSN = 4 'Add data source
Const ODBC_CONFIG_SYS_DSN = 5 'Configure (edit) data source
Const ODBC_REMOVE_SYS_DSN = 6 'Remove data source 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
Public Function Build_SystemDSN(DSN_NAME As String, Db_Path As String) Dim ret As Long, Driver As String, Attributes As String Driver = "Microsoft Access Driver (*.MDB)" & Chr(0)
Attributes = "DSN=" & DSN_NAME & Chr(0)
Attributes = Attributes & "Uid=Admin" & Chr(0) & "pwd=" & Chr(0)
Attributes = Attributes & "DBQ=" & Db_Path & Chr(0)
ret = SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, Driver, Attributes)
'ret is equal to 1 on success and 0 if there is an error
If ret <> 1 Then
' MsgBox "DSN Creation Failed"
End If End Function
1、使用 DBEngine 物件的 RegisterDatabase 方法
2、呼叫 SQLConfigDataSource API不管使用以上任何一种方法新增 DSN,一共会写入二个地方,一个是注册表,一个是 ODBC.INI。而删除 DSN 的方法同上面的第二种方法,呼叫 SQLConfigDataSource API。以下之模组以 Oracle73 Ver 2.5 为例,在 Form 的声明区中加入以下声明及模组: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 LongPublic 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'假设要产生的 DSN 为 Test,实际使用范例如下:Private Sub Command1_Click()
CreateDSN "Test"
End SubPrivate Sub Command2_Click()
DeleteDSN "Test"
End Sub'而写到系统的资料如下:1、ODBC.INI[ODBC 32 bit Data Sources]
Test=Oracle73 Ver 2.5 (32 bit)[Test]
Driver32=C:\ORAWIN95\ODBC250\sqo32_73.dll2、注册表机码:HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ODBC Data Sources
名称:Test 资料:Oracle73 Ver 2.5机码:HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\Test
名称:Description 资料:Test
名称:Driver 资料:C:\ORAWIN95\ODBC250\sqo32_73.dll
名称:Server 资料:Oracle8
名称:UserId 资料:Scott※注一及注二可任选一种,只要将不使用的方法 Mark 起来即可!
※若您想使用其他之资料库,只要将以上模组稍作修改即可!