怎样在程序中动态设置ODBC?????

iiboy 2003-08-12 05:07:08
各位,大家好!!!
小弟设计了一程序,使用了ODBC数据源!由于程序移值性问题.
我想在程序中动态设置ODBC数据源,不知道能行么??
数据为SQL Server+ODBC和ACCESS+ODBC
你可以把它写在论坛上,也可以发邮件给我:llbofchina@sina.com.cn
先谢谢你们了!
...全文
66 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lisong770818 2003-08-18
  • 打赏
  • 举报
回复
up
WorldBoy 2003-08-18
  • 打赏
  • 举报
回复
Create and Remove a DSN in Visual Basic
1.Start a New Project.
In the Advanced tab of the Options dialog box under the Tools menu, set a Conditional Compilation Argument named WIN32 equal to 1 if using Visual Basic 4.0 32-bit, or 0 if using Visual Basic 4.0 16-bit.
2.Add two CommandButtons to the default form.
3.Add the following code to the General Declarations:
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
#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

4.Add the following code into the Click event of Command1:
#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 If

5.Add the following code into the Click event of Command2:
#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 most common.
strDriver = "SQL Server"
'Set the attributes delimited by null.
'See driver documentation for a complete list of attributes.
strAttributes = "DSN=DSN_TEMP" & Chr$(0)
'To show dialog, use Form1.Hwnd instead of vbAPINull.
intRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, _
strDriver, strAttributes)
If intRet Then
MsgBox "DSN Deleted"
Else
MsgBox "Delete Failed"
End If

6.Run the project.
7.Click Command1 to add a DSN named DSN_TEMP.
8.Click Command2 to remove the DSN named DSN_TEMP.
【更新至2025年】2001-2025年上市公司数字化转型年报词频统计(吴非、赵宸宇、甄红线)(300+年报词频统计) 1、时间:2001-2025年 2、来源:上市公司年报 3、参考文献:企业数字化转型与资本市场表现——来自股票流动性的经验证据(吴非) 数字化转型如何影响企业全要素生产率(赵宸宇) 知识产权行政保护与企业数字化转型(甄红线) 4、方法说明:(1)参考吴非老师的做法,对人工智能技术、大数据技术、云计算技术、区块链技术、数字技术运用五个维度76个数字化相关词频进行统计 (2)参考赵宸宇老师的做法,对数字技术应用、互联网商业模式、智能制造、现代信息系统四个维度99个数字化相关词频进行统计 (3)参考甄红线老师的做法,对技术分类、组织赋能、数字化应用等类别下139个数字化相关词频进行统计 5、指标:年份、股票代码、公司简称、行业名称、行业代码、全文-文本总长度、仅英文-文本总长度、人工智能技术-吴、大数据技术-吴、云计算技术-吴、区块链技术-吴、数字技术运用-吴、数字技术应用-赵、互联网商业模式-赵、智能制造-赵、现代信息系统-赵、技术分类-人工智能技术-甄、技术分类-区块链技术-甄、技术分类-云计算技术-甄、技术分类-大数据技术-甄、组织赋能-人工智能技术-甄、组织赋能-云计算技术-甄、组织赋能-大数据技术-甄、组织赋能-广义数字技术-甄、数字化应用-技术创新-甄、数字化应用-流程创新-甄、数字化应用-业务创新-甄、人工智能、商业智能、图像理解、投资决策辅助系统、智能数据分析、智能机器人、机器学习、深度学习、语义搜索、生物识别技术、人脸识别、语音识别、身份验证、自动驾驶、自然语言处理、大数据、数据挖掘、文本挖掘、数据可视化、异构数据、征信、增强现实、混合现实、虚拟现实、云计算、流计算、图计算、内存计算、多方安全计算、类脑计算、绿色计算、认知计算等300+词频

807

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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