有两个数据库文件,一个是database1,里面有一个表是"老师",另一个是database2,里面有一个表是"学生".另外设置两个按钮和一个Adodc,我如何做到点按钮1让ADODC和database1连接起来,点按钮2和database2连接起来?

解决方案 »

  1.   

    用adodc的
    connectionstring
    recordsource
      

  2.   

    在command1和command2 的click事件中写代码连接数据库.连接数据库:用ADO,DAO都可以.建立两个连接conn1,conn2
      

  3.   

    连接字符串要在代码里写
    按钮1的单击事件中:
    Dim strCn As String
    Dim strSh As String
    strCn = "Provider=MSDataShape.1;Data Source=16.45.65.212(或服务器名);" & _
    "Connect Timeout=15;UID=sa;PWD=123;Database=database1;Data Provider=SQLOLEDB"
    strSh="select * from student"
    Adodc1.ConnectionString = strCn
    Adodc1.RecordSource = strSh
    Set Fg2.DataSource = Adodc1(如果要绑定网格控件,就加这句)
    按钮2的单击事件中:
    Dim strCn As String
    Dim strSh As String
    strCn = "Provider=MSDataShape.1;Data Source=16.45.65.212(或服务器名);" & _
    "Connect Timeout=15;UID=sa;PWD=123;Database=database2;Data Provider=SQLOLEDB"
    strSh="select * from teacher"
    Adodc1.ConnectionString = strCn
    Adodc1.RecordSource = strSh
    Set Fg2.DataSource = Adodc1(如果要绑定网格控件,就加这句)这样就可以了~试试看
      

  4.   

    很容易的!
    用MSRDC控件!
    指定数据源就可以了