动态生成dsn的例子,帮我看看问题出在哪?

lizhenlz 2002-10-22 01:38:14
'''''''''''''''''''''''''''''''''''''
'''动态生成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
SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, strDriver, strAttributes)
报错!未将对象引用设置到对象的实例。
请帮我看看,问题出在哪呢?
...全文
26 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

16,554

社区成员

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

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