
常用软件类: |
|杀毒安全 | |联络聊天 | |网络软件 | |多媒体类 | |系统工具 | |图形图像 | |系统工具 | |应用软件 | |行业软件 |
开发设计类: |
|动画制作 | |图像处理 | |3D设计 | |操作系统 | |站长学院 | |网络相关 | |WEB设计 | |数据库类 | |程序开发 |
如何设置对VB数据库连接的动态路径
我个人因为经常作一些数据库方面的程序,对于程序间如何与数据库进行接口的问题之烦是深有体会,因为VB在数据库链接的时候,一般是静态,即数据库存放的路径是固定的,如用VB的DATA,adodc,DataEnvironment 等到作数据库链接时,如果存放数据库的路径被改变的话,就会找不到路经,真是一个特别烦的事。
笔者的解决方法是利用app.path 来解决这个问题。
一、用data控件进行数据库链接,可以这样:
在form_load()过程中放入:
| private form_load() Dim str As String ’定义 str = App.Path If Right(str, 1) <> "\" Then str = str + "\" End If data1.databasename=str & "\数据库名" data1.recordsource="数据表名" data1.refresh sub end |
| private form_load () Dim str As String ’定义 str = App.Path If Right(str, 1) <> "\" Then str = str + "\" End If str = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & str & "\tsl.mdb" Adodc1.ConnectionString = str Adodc1.CommandType = adCmdText Adodc1.RecordSource = "select * from table3" Adodc1.Refresh end sub |
| On Error Resume Next If DataEnvironment1.rsCommand1.State <> adStateClosed Then DataEnvironment1.rsCommand1.Close ’如果打开,则关闭 End If ’i = InputBox("请输入友人编号:", "输入") ’If i = "" Then Exit Sub DataEnvironment1.Connection1.Open App.Path & "\userdatabase\tsl.mdb" DataEnvironment1.rsCommand1.Open "select * from table3 where 编号=’" & i & "’" ’Set DataReport2.DataSource = DataEnvironment1 ’DataReport2.DataMember = "command1" ’DataReport2.show end sub |
| dim conn as new adodb.connection dim rs as new adodb.recordset dim str str = App.Path If Right(str, 1) <> "\" Then str = str + "\" End If str = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & str & "\tsl.mdb" conn.open str rs.cursorlocation=aduseclient rs.open "数据表名",conn,adopenkeyset.adlockpessimistic 用完之后关闭数据库: conn.close set conn=nothing |
| Dim Statement As String Statement = "X=" + Text1.Text + vbCrLf + _ "Y=" + Text2.Text + vbCrLf + _ "MsgBox ""计算结果="" & Y " ScriptControl1.ExecuteStatement( Statement |
| Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Const SWP_NOMOVE = &H2 ’不更动目前视窗位置 Const SWP_NOSIZE = &H1 ’不更动目前视窗大小 Const HWND_TOPMOST = -1 ’设定为最上层 Const HWND_NOTOPMOST = -2 ’取消最上层设定 Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE ’将 APP 视窗设定成永远保持在最上层 SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS ’取消最上层设定 SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS |
| Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long |
| Intranet: ShellExecute Me.hWnd, "open", "http://Intranet主机/目录", "", "", 5 Internet: ShellExecute Me.hWnd, "open", "http://www.ruentex.com.tw", "", "", 5 |