如何使用ADO控件對兩個表進行查詢,把結果顯示在Datagrid控件中;
我使用SQL語句:
  select 表1.id,表2.name from 表1,表2 where 表1.id=表2.id
但是好像,這樣的SQL查詢語句在vb中行不通;
有沒有哪位高手能告訴我,為我解惑啊!
是不是ADO不支持SQL多表查詢語句?

解决方案 »

  1.   

    與ADO沒有關係的,問題是你使用的什麽數據庫? on error resume next dim adocon as adodb.connection
     dim adores as adores.recordSet set adocon = new adodb.connection
         adocon.connectionString = "driver={SQL SERVER};uid=sa;pwd=;database=你的數據庫名稱"
         adocon.connectionTimeout = 30
         adocon.open set adores = adocon.execute("select 表1.id,表2.name from 表1,表2 where 表1.id=表2.id") do while not adores.eof
        adores("id")         '  /*  取id列值   */
        adores("name")       '  /*  取name列值  */
       
         ...
         ...    在这个地方可以将值放入到datagrid中去,使用 cell 属性
         ...
        adores.movenext
     loop adores.close
     set adores = nothing adocon.close
     set adocon = nothing
      

  2.   

    建议使用mshflexgrid控件。
    直接set mshflexgrid1.datasoure = Temprs就行了。
      

  3.   

    adodc1.datasoure ="select 表1.id,表2.name from 表1,表2 where 表1.id=表2.id
    "
    adodc1.refresh爲何,DATAGRID控件上不能顯示結果;
    而且報錯;
      

  4.   

    设置
    sql="select 表1.id,表2.name from 表1,表2 where 表1.id=表2.id
    "
    adodc1.resource=sql
    datagrid1.datasource=adodc1
      

  5.   

    請問使用ADO控件時,爲何使用delete 語句會出現報錯信息;
    請指點,定會高分相送;
    如:Adodc1.RecordSource = "DELETE FROM biao1 WHERE id='3'"
        adodc1.refresh
      

  6.   

    用inner    join 试一试
      

  7.   

    With Me.Adodc1
            .ConnectionString = g_Conn
            .RecordSource = strSQL
        End With
        With Me.DataGrid1
            Set .DataSource = Me.Adodc1
            Me.Adodc1.Refresh
        End With
      

  8.   

    其实是一样的
    只是Sql语句多点就是啊
    dim strSql as string 
    ADodc1.connectionstring=dbdev.gconn.connectionstringstrSql="select * from 表1,表2 where 表1。id=表2.id
    Adodc1.recordsource=strSql
    Adodc1.refreshset datagrid1.datasource=Adodc1