如何使用ADO控件對兩個表進行查詢,把結果顯示在Datagrid控件中;
我使用SQL語句:
select 表1.id,表2.name from 表1,表2 where 表1.id=表2.id
但是好像,這樣的SQL查詢語句在vb中行不通;
有沒有哪位高手能告訴我,為我解惑啊!
是不是ADO不支持SQL多表查詢語句?
我使用SQL語句:
select 表1.id,表2.name from 表1,表2 where 表1.id=表2.id
但是好像,這樣的SQL查詢語句在vb中行不通;
有沒有哪位高手能告訴我,為我解惑啊!
是不是ADO不支持SQL多表查詢語句?
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
直接set mshflexgrid1.datasoure = Temprs就行了。
"
adodc1.refresh爲何,DATAGRID控件上不能顯示結果;
而且報錯;
sql="select 表1.id,表2.name from 表1,表2 where 表1.id=表2.id
"
adodc1.resource=sql
datagrid1.datasource=adodc1
請指點,定會高分相送;
如:Adodc1.RecordSource = "DELETE FROM biao1 WHERE id='3'"
adodc1.refresh
.ConnectionString = g_Conn
.RecordSource = strSQL
End With
With Me.DataGrid1
Set .DataSource = Me.Adodc1
Me.Adodc1.Refresh
End With
只是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