动态生成dsn的例子,帮我看看问题出在哪?
'''''''''''''''''''''''''''''''''''''
'''动态生成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)
报错!未将对象引用设置到对象的实例。
请帮我看看,问题出在哪呢?