标题:多表查询
只看楼主
jsyyqyyq
Rank: 1
等 级:新手上路
帖 子:21
专家分:7
注 册:2011-12-21
结帖率:50%
已结贴  问题点数:20 回复次数:11 
多表查询
Private Sub Form_Load()
Form4.Text1.Text = Form2.Text1.Text
   Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\win.mdb;Persist Security Info=False"
    Adodc1.RecordSource = "select select 读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号"
    Adodc1.Refresh
    Set DataGrid1.DataSource = Adodc1
End Sub
----------------------------------------------------------------------------------------------------
Private Sub Command1_Click()
Call CX     '调用函数
End Sub
----------------------------------------------------------------------------------------------
Public Sub CX()
If Check1.Value = 1 And Check2.Value = 0 Then
Adodc1.RecordSource = "select 读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号 and like'" & Trim(Text2.Text) & "' "
    Adodc1.Refresh
 ElseIf Check1.Value = 0 And Check2.Value = 1 Then
Adodc1.RecordSource = "select 读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号 and year(出生日期)=" & Trim(Text3.Text) & ""
    Adodc1.Refresh
    ElseIf Check1.Value = 1 And Check2.Value = 1 Then
Adodc1.RecordSource = "select 读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号 and 读者编号 like'" & Trim(Text2.Text) & "'and year(出生日期)=" & Trim(Text3.Text) & ""
    Adodc1.Refresh
 End If
End Sub
-------------------------------------------------------------------------
我做的一个多表查询 表名 B,C 那位高手看看我哪错了,我是新手底子不扎实请指点下
搜索更多相关主题的帖子: 书籍 姓名 False where 读者 
2012-02-01 10:02
ta8607
Rank: 4
等 级:业余侠客
帖 子:377
专家分:244
注 册:2007-9-22
得分:5 
如果B,C表中都有 讀者編號 在查詢時就應該在查詢時加表名
select b.读者编号,读者姓名,书籍名称 ....
另外
Adodc1.RecordSource = "select 读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号 and like'" & Trim(Text2.Text) & "' "
這裡還要指明列名是什麼

不理会流言蜚语,努力做好份内事情,只做自己.
2012-02-01 10:14
jsyyqyyq
Rank: 1
等 级:新手上路
帖 子:21
专家分:7
注 册:2011-12-21
得分:0 
Public Sub CX()
If Check1.Value = 1 And Check2.Value = 0 Then
Adodc1.RecordSource = "select b.读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号 and 读者编号 like'" & Trim(Text2.Text) & "' "
    Adodc1.Refresh
 ElseIf Check1.Value = 0 And Check2.Value = 1 Then
Adodc1.RecordSource = "select b.读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号 and year(出生日期)=" & Trim(Text3.Text) & ""
    Adodc1.Refresh
    ElseIf Check1.Value = 1 And Check2.Value = 1 Then
Adodc1.RecordSource = "select b.读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号 and 读者编号 like'" & Trim(Text2.Text) & "'and year(出生日期)=" & Trim(Text3.Text) & ""
    Adodc1.Refresh
 End If
End Sub
---------------------------------
Private Sub Form_Load()
Form4.Text1.Text = Form2.Text1.Text
   Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\win.mdb;Persist Security Info=False"
    Adodc1.RecordSource = "select select b.读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号"
    Adodc1.Refresh
    Set DataGrid1.DataSource = Adodc1
End Sub
-------------------------------------
还是有错 高手请再指点下
2012-02-01 11:20
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
得分:5 
Adodc1.RecordSource = "select select b.读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号"
怎么会有两个select?多表查询我一般用join,这样查我还没用过,可以在access里建个查询试试
2012-02-01 11:41
jsyyqyyq
Rank: 1
等 级:新手上路
帖 子:21
专家分:7
注 册:2011-12-21
得分:0 
哪位大哥帮帮忙啊啊
2012-02-01 13:19
apple0072011
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:9
帖 子:249
专家分:989
注 册:2011-8-17
得分:5 
Private Sub Form_Load()
Form4.Text1.Text = Form2.Text1.Text
   Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\win.mdb;Persist Security Info=False"
    Adodc1.RecordSource = "select select b.读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号"
    Adodc1.Refresh
    Set DataGrid1.DataSource = Adodc1
End Sub
红字部分:两个select 是什么意思?

天道酬勤
2012-02-01 15:16
jsyyqyyq
Rank: 1
等 级:新手上路
帖 子:21
专家分:7
注 册:2011-12-21
得分:0 
Public Sub CX()
If Check1.Value = 1 And Check2.Value = 0 Then
Adodc1.RecordSource = "select b.读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号 and 读者编号 like'" & Trim(Text2.Text) & "' "
    Adodc1.Refresh
ElseIf Check1.Value = 0 And Check2.Value = 1 Then
Adodc1.RecordSource = "select b.读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号 and year(出生日期)=" & Trim(Text3.Text) & ""
    Adodc1.Refresh
    ElseIf Check1.Value = 1 And Check2.Value = 1 Then
Adodc1.RecordSource = "select b.读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号 and 读者编号 like'" & Trim(Text2.Text) & "'and year(出生日期)=" & Trim(Text3.Text) & ""
    Adodc1.Refresh
End If
End Sub
---------------------------------
Private Sub Form_Load()
Form4.Text1.Text = Form2.Text1.Text
   Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\win.mdb;Persist Security Info=False"
    Adodc1.RecordSource = "select b.读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号"
    Adodc1.Refresh
    Set DataGrid1.DataSource = Adodc1
End Sub
-------------------------------------
还是有错 高手请再指点下
2012-02-01 20:11
Artless
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:4211
专家分:28888
注 册:2009-4-8
得分:5 
以下是引用jsyyqyyq在2012-2-1 10:02:55的发言:

Private Sub Form_Load()
Form4.Text1.Text = Form2.Text1.Text
   Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\win.mdb;Persist Security Info=False"
    Adodc1.RecordSource = "select select 读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号"
    Adodc1.Refresh
    Set DataGrid1.DataSource = Adodc1
End Sub
----------------------------------------------------------------------------------------------------
Private Sub Command1_Click()
Call CX     '调用函数
End Sub
----------------------------------------------------------------------------------------------
Public Sub CX()
If Check1.Value = 1 And Check2.Value = 0 Then
Adodc1.RecordSource = "select 读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号 and like'" & Trim(Text2.Text) & "' "
    Adodc1.Refresh
 ElseIf Check1.Value = 0 And Check2.Value = 1 Then
Adodc1.RecordSource = "select 读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号 and year(出生日期)=" & Trim(Text3.Text) & ""
    Adodc1.Refresh
    ElseIf Check1.Value = 1 And Check2.Value = 1 Then
Adodc1.RecordSource = "select 读者编号,读者姓名,书籍名称 from b,c where b.读者编号=c.读者编号 and 读者编号 like'" & Trim(Text2.Text) & "'and year(出生日期)=" & Trim(Text3.Text) & ""
    Adodc1.Refresh
 End If
End Sub
-------------------------------------------------------------------------
我做的一个多表查询 表名 B,C 那位高手看看我哪错了,我是新手底子不扎实请指点下

读者编号,读者姓名,书籍名称 from b,c

无知
2012-02-02 00:05
jsyyqyyq
Rank: 1
等 级:新手上路
帖 子:21
专家分:7
注 册:2011-12-21
得分:0 
版主 我知道本人水平很差 你是高手就具体点指导下 不要冷嘲热讽
如果水平高的话就不需要上网请教了 寸有所长寸有所短
谢谢  还请高手具体指点下
2012-02-02 09:55
ta8607
Rank: 4
等 级:业余侠客
帖 子:377
专家分:244
注 册:2007-9-22
得分:0 
读者编号 like'" & Trim(Text2.Text) & "' "
like 後面加一空格

不理会流言蜚语,努力做好份内事情,只做自己.
2012-02-02 14:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-360220-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.437524 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved