[AccessD] .Net Form Binding (was: Goodbye Leszynski/Reddick?)

Dan Waters df.waters at outlook.com
Mon Jan 26 08:48:48 CST 2015


Hi Shamil,

In a car with the steering wheel on the right, I hope the manual gear pattern is not a mirror image!  ;-)

For binding forms, I create a Linq to SQL (LtS) query and set that as the form's bindingsource datasource like this:

---------------------------------------------------------------------
SIMPLE EXAMPLE
Dim LQMain = From a In DCAppMain.tblPeopleMain
    Where a.PeopleID = intPeopleID
Me.tblPeopleMainBindingSource.DataSource = LQMain

This is as simple as it gets.  I'm glad I initially decided to go with LtS - simple and flexible.  I only rarely use ADO code in .Net coding (i.e. delete all rows from a temp table).

---------------------------------------------------------------------  
COMPLEX EXAMPLE
Select Case stgDatasetFilter

    Case "My Open Records"

        '-- This will filter to the records where the user is the assessor and record is not closed, or where the user has been assigned to an opportunity and the opportunity is not completed and the record is in Improvement stage

        '-- Assessor
        Dim LQMyRecords1 = From a In DCAppMain.tblS5Main
            Where a.AssessorID = SV.CurrentPersonID And a.Stage <> "Closed"
            Select a.S5MainID, a.Stage

        '-- Assignment
        Dim LQMyRecords2 = (From b In DCAppMain.tblS5Main Join c In DCAppMain.tblS5Opportunities On b.S5MainID Equals c.S5MainID
            Where b.Stage = "Improvement" And c.AssignedToID = SV.CurrentPersonID And c.CompletedByID = False
            Select S5MainID = b.S5MainID, b.Stage)

        Dim LQMyRecords3 = From d In LQMyRecords1.Union(LQMyRecords2)
            Order By d.S5MainID
            Select d.S5MainID, d.Stage

        If LQMyRecords3.Any = False Then
            stgPrompt = "There are no open 5S Records where you are the Assessor or where you are Assigned to an Opportunity."
            MessageBox.Show(stgPrompt, "No Records", MessageBoxButtons.OK, MessageBoxIcon.Information)
            cboShow.Text = "All Records"
            Exit Sub
        End If

        Dim LQMyRecords4 = From d In DCAppMain.tblS5Main Join e In LQMyRecords3 On d.S5MainID Equals e.S5MainID
            Order By d.S5MainID
            Select d.S5MainID, d.Stage, d.AceCellID, d.AceCellSubID, d.AssessorID, d.AssessorDate, d.S5Sort, d.S5Straighten, d.S5Shine, d.S5Standardize, d.S5Sustain, d.ClosedDate

        Me.TblS5MainBindingSource.DataSource = LQMyRecords4
        Me.TblS5MainBindingSource.MoveLast()

This example shows how to use LtS in a more complex way.  I've unioned querys 1 and 2 to see if any records apply to the person trying to filter the screen.  Then used query 3 joined with the Main table to finally get the form's datasource.  And, I've only shown one of the many cases a user could select to filter this screen.

LtS is optimized for use with SQL Server databases to provide good performance.  Some people say that Microsoft has stopped supporting LtS - no way!  It's just that LtS is no longer a work in progress like Linq to Entities has been for the last several years.  In any case, MS would not stop supporting something that pulls together two of their premier products!

Thanks!
Dan

-----Original Message-----
From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Salakhetdinov Shamil
Sent: Monday, January 26, 2015 1:36 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Goodbye Leszynski/Reddick?

 Hi Dan --

<<<
Now, when working in Access VBA, I feel like I'm driving a car that doesn't have any gauges! 
>>>
So true.

<<<
My .Net work so far is in windows forms only in VB, and those apps are very form-centric. 
So, I just haven't seen an advantage to setting up a class for a Customer, or part, or almost anything else. 
>>>
Do you use .NET Windows Forms bound forms with BindingSource and BindingNavigator and ADO.NET datasets?

<<<
Speaking of which, I have to go drive that car right now ... ;-)
>>>
That'd keep you concentrated on the road - not bad after all :) (I used to switch between a car with automatic and manual transmissions, the one with responsive driving wheel, throttle, clutch and brakes and the one with all that levers being very rigid, even used manual transmission manipulating it by my left hand while driving abroad a right-driving-wheel car keeping driving on the left side of the road - it was very refreshing! :) )

Thank you.

-- Shamil





More information about the AccessD mailing list