Option Explicit
'Constant Declaration
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 Pointer
'Function Declare
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
Private Sub Command1_Click()
Dim intRet As Long
Dim strDriver As String
Dim strAttributes As String
'Set the driver to SQL Server because it is most common.
strDriver = "SQL Server"
'Set the attributes delimited by null.
'See driver documentation for a complete
'list of supported attributes.
strAttributes = "SERVER=IT" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=DSN_TEMP" & Chr$(0)
strAttributes = strAttributes & "DSN=TEMP" & Chr$(0)
strAttributes = strAttributes & "DATABASE=pubs" & Chr$(0)
strAttributes = strAttributes & "UID=sa" & Chr$(0)
strAttributes = strAttributes & "PWD=123456" & Chr$(0)
Debug.Print strAttributes
'To show dialog, use Form1.Hwnd instead of vbAPINull.
intRet = SQLConfigDataSource(Me.hWnd, ODBC_ADD_DSN, strDriver, strAttributes)
If intRet Then
MsgBox "DSN Created"
Else
MsgBox "Create Failed"
End IfEnd Sub
没有任何错误提示!为什么添加不成功呢》?
请高手指教!!!!!!!!!!!
'Constant Declaration
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 Pointer
'Function Declare
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
Private Sub Command1_Click()
Dim intRet As Long
Dim strDriver As String
Dim strAttributes As String
'Set the driver to SQL Server because it is most common.
strDriver = "SQL Server"
'Set the attributes delimited by null.
'See driver documentation for a complete
'list of supported attributes.
strAttributes = "SERVER=IT" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=DSN_TEMP" & Chr$(0)
strAttributes = strAttributes & "DSN=TEMP" & Chr$(0)
strAttributes = strAttributes & "DATABASE=pubs" & Chr$(0)
strAttributes = strAttributes & "UID=sa" & Chr$(0)
strAttributes = strAttributes & "PWD=123456" & Chr$(0)
Debug.Print strAttributes
'To show dialog, use Form1.Hwnd instead of vbAPINull.
intRet = SQLConfigDataSource(Me.hWnd, ODBC_ADD_DSN, strDriver, strAttributes)
If intRet Then
MsgBox "DSN Created"
Else
MsgBox "Create Failed"
End IfEnd Sub
没有任何错误提示!为什么添加不成功呢》?
请高手指教!!!!!!!!!!!
解决方案 »
- 請教TDBGrid欄位設置
- 怎么让某个目录下的程序运行时以非管理员权限运行?
- VB 怎样读取文本文件的数字到文本框1,2,3,4?
- 在VB中如何才能将ACCESS数据库的表导成excel
- *****我想对网络运用多点认识,请推荐你认为优秀的书
- VB在文件读写过程中产生乱码(救命)
- 如何选取一个ACCESS表后,得到这个表的表结构?
- 怎样在vb中显示autocad图,同时不前台显示?
- 怎么拖动无标题的窗体
- 在用VB编程时发现如果在调用API时如果不采集返回值就不能用括号将参数括起来,否则会有错误。反之如果要返回值,就必须不要括号。但现在
- 5000元购买各类大型程序源码。或用我的ERP交换。
- 哪为仁兄知道水晶报表8。0的安装cd key code??
http://support.microsoft.com/support/kb/articles/Q171/1/46.asp
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 Pointer 'Function Declare
#If Win32 Then 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
#Else
Private Declare Function SQLConfigDataSource Lib "ODBCINST.DLL" _
(ByVal hwndParent As Integer, ByVal fRequest As Integer, ByVal _
lpszDriver As String, ByVal lpszAttributes As String) As Integer
#End If
Private Sub Command1_Click()
#If Win32 Then
Dim intRet As Long
#Else
Dim intRet As Integer
#End If
Dim strDriver As String
Dim strAttributes As String 'Set the driver to SQL Server because it is most common.
strDriver = "SQL Server"
'Set the attributes delimited by null.
'See driver documentation for a complete
'list of supported attributes.
strAttributes = "SERVER=SomeServer" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)
strAttributes = strAttributes & "DSN=DSN_TEMP" & Chr$(0)
strAttributes = strAttributes & "DATABASE=pubs" & Chr$(0)
'To show dialog, use Form1.Hwnd instead of vbAPINull.
intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
strDriver, strAttributes)
If intRet Then
MsgBox "DSN Created"
Else
MsgBox "Create Failed"
End IfEnd Sub我试过,行的!看一下你的控制面板里的---数据源(ODBC)
你能把你的QQ或MSN告诉我么?
你把用户名和密码。。
是可以用的。