Solved

Pass OledbConnection in between forms

Posted on 2004-10-28
230 Views
Last Modified: 2010-04-24
Hello all,

I need to know how to pass a connection (or datareader etc.) between forms in vb.net.

I have 2 forms, on the first one the user drags text from a datagrid and drops it into a listbox. On the drop I open a connection and search for results from a database. If there is only 1 result then the result gets added to the listbox, however, if there is more than one result i want to open another form displaying the results for the user to select from.

I'd prefer to use the same connection I've already opened on the first form on the second form as well rather than opening another connection.

Is there any way to do this other than declaring a public connection in a module?

Alternatively, can I do the search on the first form to a datareader or dataset and then pass this to the second form?


Thanks
Charel

0
Question by:cpk68
    2 Comments
     
    LVL 25

    Accepted Solution

    by:
    If lets say that form2 has a datagrid you want to fill with the results from the first form you can do something like this

    FORM1.

    ^Pseudo Code
    dim ds as new dataset
    'your search
    if ds.rows.count > 1 then
      dim f as new form2
      f.datagrid1.datasource = ds.tables(0)
      f.show
    elseif ds.rows.count = 1 then
      'add to listbox
    else
      'no rows found
    endif
    0
     

    Author Comment

    by:cpk68
    Thank you kindly. Almost too simple :o)
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now