Results 1 to 15 of 15

Thread: sql involving three tables

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Location
    philippines
    Posts
    98

    Question sql involving three tables

    hello..i can't get my code to work..here's the details
    i have three tables

    table 1 :Company_Profile
    fields: address,comp_no

    table 2: Project_Info
    fields: pro_no, title

    table 3: Company_Project
    fields : com_no, pro_no

    I want to link the tree tables..I have a search button..the input is address..
    So, I need to get the pro_no and comp_no of the address given including the title..

    this is my current code:

    adodc1.recordsource = "select * from address, a.comp_no, b.pro_no from Company_Profile,Company_Profile a,Project_Info b where address = txt2.text and a.comp_no = comp_no and b.pro_no = a.pro_no"
    adodc1.refresh..


    please..i Need it so bad..
    tnx..
    Last edited by puzzleofurheart_23; Jun 1st, 2008 at 03:03 AM.

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: sql involving three tables

    This is one way

    Code:
    "SELECT Company_Project.pro_no AS Pro_No, Company_Project.comp_no AS Comp_No FROM Company_Project, Company_Profile WHERE Company_Profile.Address = '" & txt2.text & "'"

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Location
    philippines
    Posts
    98

    Re: sql involving three tables

    Quote Originally Posted by lintz
    This is one way

    Code:
    "SELECT Company_Project.pro_no AS Pro_No, Company_Project.comp_no AS Comp_No FROM Company_Project, Company_Profile WHERE Company_Profile.Address = '" & txt2.text & "'"
    how can I get the title?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: sql involving three tables

    Ad that field to your select field list.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Location
    philippines
    Posts
    98

    Re: sql involving three tables

    Quote Originally Posted by RobDog888
    Ad that field to your select field list.
    i already did..but i want to filter it by pro_no..can you tell me what's wrong this code :

    Adodc1.RecordSource = "SELECT Company_Profile.address AS address, Project_Info.title AS title, Project_Info.pro_no as Pro_no1, Company_Projects.pro_no as Pro_no2 FROM Company_Projects, Company_Profile, Project_Info WHERE Project_Info.pro_no = Company_Projects.pro_no And Company_Profile.contact_lname like " & hold
    Adodc1.Refresh

    I have an error..object not required.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: sql involving three tables

    Ah you are using that ADODC data bound control. This makes things more difficult. Using all ADO code instead makes it easier but for now are you binding your controls to the fields in the data control?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Location
    philippines
    Posts
    98

    Re: sql involving three tables

    Quote Originally Posted by RobDog888
    Ah you are using that ADODC data bound control. This makes things more difficult. Using all ADO code instead makes it easier but for now are you binding your controls to the fields in the data control?
    I have textbox where the address will be entered..and On the interactive change of the textbox, i have a datagrid that will show the matched address. I use ADODC so that it will show all the data on real time..I need to have a double condition so that I can filter the result by pro_no bcoz it appears many times on the grid.

    I can't get it to work.

    Can you help me?

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: sql involving three tables

    I dont believe the adodc control has a fileter property but if you had used pure ado code then all these issues wouldnt be an issue. I dont use the ado data control for these reasons. Perhaps someone who does may know a way around that.

    the only thing I can think of is to re execute a sql statement that will add the extra filtering in the where clause.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: sql involving three tables

    Thread moved to Database Development forum

    Quote Originally Posted by puzzleofurheart_23
    Adodc1.RecordSource = "SELECT Company_Profile.address AS address, Project_Info.title AS title, Project_Info.pro_no as Pro_no1, Company_Projects.pro_no as Pro_no2 FROM Company_Projects, Company_Profile, Project_Info WHERE Project_Info.pro_no = Company_Projects.pro_no And Company_Profile.contact_lname like " & hold
    Adodc1.Refresh

    I have an error..object not required.
    I've never heard of that error.. I presume it was actually "Object required".

    If that is the case, check what Adodc1 is - as that not being an Object (a control etc) is the only thing which could cause the error.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: sql involving three tables

    I think if adodc code is in form load it may give that error as the control isnt initialized yet perhaps.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: sql involving three tables

    I dont know about the ADODC, but a SQL with INNER JOIN could get you the information.

    eg:
    Code:
    SELECT * FROM Company_Project INNER JOIN Project_Info  ON Company_Project.pro_no = Project_Info. pro_no WHERE Company_Profile.Address = '" & txt2.text & "'"
    You could get Title from this.

    Why dont you use ADO instaed of ADODC?

    IIF(Post.Rate > 0 , , )

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Location
    philippines
    Posts
    98

    Re: sql involving three tables

    Quote Originally Posted by zeezee
    I dont know about the ADODC, but a SQL with INNER JOIN could get you the information.

    eg:
    Code:
    SELECT * FROM Company_Project INNER JOIN Project_Info  ON Company_Project.pro_no = Project_Info. pro_no WHERE Company_Profile.Address = '" & txt2.text & "'"
    You could get Title from this.

    Why dont you use ADO instaed of ADODC?

    i don't know how to use ado..can you give a good link where I could learn about it?

  13. #13
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: sql involving three tables

    See the "Classic VB - ADO" section of our Database Development FAQs/Tutorials (at the top of this forum)

  14. #14
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: sql involving three tables

    i don't know how to use ado..can you give a good link where I could learn about it?
    Certainly, Check our own DB FAQs.

    http://www.vbforums.com/showthread.php?t=337051#ado

    http://www.vbforums.com/showthread.php?t=337051#bound
    http://www.vbforums.com/showthread.php?t=337051

    Data Bound Control is good, its easy and not much PIA, but its still better if you know whats going on.
    Databound control is for lazy people who doesnt want to learn to do better. (no any offense to you though )

    IIF(Post.Rate > 0 , , )

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: sql involving three tables

    In his other thread it was pointed out that his current statement is missing double quotes on part of the statemet.

    http://www.vbforums.com/showthread.php?t=525189
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width