以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  动态切换外部数据表  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=92933)

--  作者:pyh6918
--  发布时间:2016/11/16 17:04:00
--  动态切换外部数据表

Dim s As String = "Provider=SQLOLEDB.1;Password=NFTH12345;Persist Security Info=True;User ID=jnmm;Initial Catalog=jnmmqzhzp;Data Source=110.2.0.200"
If connections.Contains("testd") = True Then
    If Connections.TryConnect(s) = False Then
        MessageBox.Show("此操作需要连接网络,请检查!")
        Return
    End If
Else
    Dim cn As Connection  =  Connections("testd")
    Connections.Add("testd",s)
    If Connections.TryConnect(s) = False Then
        MessageBox.Show("此操作需要连接网络,请检查!")
        Return
    End If
    DataTables("注册明细表").ChangeConnection("testd")
End If

 

系统打开时,注册明细表是打开着的,在ACCESS外部数据源下。

在打开注册窗口时,切换为SQL外部数据库,但是在打开注册窗口时先提示【testd数据源不存在】,然后窗口正常打开,数据表也切换成功。

请问怎么才能不出现错误提示?


--  作者:有点蓝
--  发布时间:2016/11/16 17:23:00
--  
去掉这句:Dim cn As Connection  =  Connections("testd")
--  作者:pyh6918
--  发布时间:2016/11/16 17:39:00
--  
谢谢