Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2007, 07:54 AM
Registered User
 
Join Date: Jul 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Many-To-Many Combo Problem

Ok I have 3 tables:

tblEmployee
tblEmployeeProject
tblProject

and I have 2 combo boxes:
lstProj
lstAvailProj

I am using this for my script:

Private Sub RequeryLists()

    ' declare local variables
    Dim strSource As String


    ' create source for "Project" list box
   strSource = "SELECT projectID FROM tblEmployeeProject " _
        & " WHERE employeeID = " & employeeID & ";"

    ' display Project Linked to Employees in list box
   lstProj.RowSource = strSource


    ' create source for "Available Projects" list box
   strSource = "SELECT projectID FROM tblProject " _
        & " WHERE projectID NOT IN " _
        & "(SELECT projectID FROM tblEmployeeProject " _
        & " WHERE employeeID = " & employeeID & ")" _
        & " ORDER BY 1 asc ; "

    ' display Projects still available in list box
   lstAvailProj.RowSource = strSource

Exit_RequeryLists:


    Exit Sub


Err_RequeryLists:


   MsgBoxErr.Description
    Resume Exit_RequeryLists


End Sub


----------------------------------------------------------

I have a button that runs the RequeryLists script, but
instead of the data from the tables coming up, just the
sql is printed in the box, the ";" however, is not in the
combo boxes. Is the script removing it or did I mess
something up? I have checked my SQL and that is right
when i just run a query with the SQL the data does come
up. Any help thanks

-Steve

 
Old July 19th, 2007, 08:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. you are a little confused ;)

see this: you are passing a Sql to the combo, but you are not passing any conection string to it so how will the combo connect to something??
Anyway, the above is not the method to do that.. One simple way to do this is to pass to the combo a datatable filled, and you only have to specify which column to show and which one to use as value.

Example:
Code:
        With yourcombo
            .DisplayMember = "Column to show"
            .ValueMember = "Column to use as value"
            .DataSource = AdataTable 'Can be others sources
            .SelectedIndex = -1 'to put it empty at the beginning
        End With


And one question.. why are you talking about scripts, there is no scripts in here, maybe functions or procedures...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old July 19th, 2007, 08:15 AM
Registered User
 
Join Date: Jul 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok i meant functions in my VB script sorry :p

Ok, so I can do that with both combo boxes that i have?

I want to show a list of projects that people are currently
on, and projects that are still available to them without
listing the same project twice.

Can i use .DataSource = (my SQL statement) ?

Thanks for quick response.
 
Old July 19th, 2007, 08:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

again, no.. your sql statement is that, just a string.. it's doesn't even tell the control where to look for the info..
you have to pass a data structure to the combo, which was filled with all the actual data... somewhere you have to connect to your database and pull the data...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo box problem diegoblin Beginning VB 6 2 October 4th, 2006 05:32 PM
Combo Box Problem munrrob Access 1 September 21st, 2006 10:35 AM
Problem Using Combo Boxes munrrob Access VBA 1 August 14th, 2006 12:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.