动态生成dsn的例子,帮我看看,谢谢!!!很急!

lizhenlz 2002-10-19 10:59:21

'''''''''''''''''''''''''''''''''''''
'''动态生成dsn'''''''''''''''''''''
''''''''''''''''''''''''''''''''''
Public 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 Const ODBC_ADD_DSN = 1 ' Add data source
Public Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
Public Const ODBC_REMOVE_DSN = 3 ' Remove data source
Public Const vbAPINull As Long = 0 ' NULL Pointer
Public Const STR_DSN_IMPORT As String = "llz"

Public Function AddImportDSN(ByVal strPath As String) As Long
Dim intRet As Long
Dim strDriver As String
Dim strAttributes As String

'Set the driver to SQL Server because it is most common.
strDriver = "Microsoft Visual FoxPro Driver"
'Set the attributes delimited by null.
'See driver documentation for a complete
'list of supported attributes.
strAttributes = ""
strAttributes = strAttributes & "DSN=" + STR_DSN_IMPORT + Chr(0)
strAttributes = strAttributes & "UID=" & Chr(0)
strAttributes = strAttributes & "Deleted = Yes" & Chr(0)
strAttributes = strAttributes & "Null=Yes" & Chr(0)
strAttributes = strAttributes & "Collate = Machine" & Chr(0)
strAttributes = strAttributes & "BackgroundFetch = Yes" & Chr(0)
strAttributes = strAttributes & "Exclusive = No" & Chr(0)
strAttributes = strAttributes & "SourceType = DBF" & Chr(0)
strAttributes = strAttributes & "SourceDB=" & strPath & Chr(0)
'To show dialog, use Form1.Hwnd instead of vbAPINull.

SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, strDriver, strAttributes)
'intRet =
'AddImportDSN = intRet
End Function


Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
AddImportDSN("c:\mm")
End Sub
...全文
21 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lizhenlz 2002-10-19
  • 打赏
  • 举报
回复
SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, strDriver, strAttributes)
报错!未将对象引用设置到对象的实例。

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧