Trying to understand Records

Troy

Well-known member
Joined
Feb 7, 2005
Messages
153
Programming Experience
10+
Let's say I have a database setup with 2 tables

The first is CONTACTS the second PACKAGE

Both tables have the field CONTACTID

This is because the first table contains primary customer information. Name, Address, etc.

The Second contain's products they have purchased. Since they might have repeat purchases they can add more entries. So this table also has CONTACTID to associate the record to the CONTACTS Table as well as PACKAGEID to give it it's own unique ID.

Is there a way to bind a BindingNavigator to a Table but limit it to only cycling through certain records ..

example setting up a Binding Navigator that allows me to display only PACKAGE Table information with the same CONTACTID as the first Table?

Man lol I almost lost myself trying to explain this I sure hope you can make heads or tails of what I'm trying to say. LOL

by the way here is an example of my binding statements which seem to work but are displaying the entire information not just those with the same CONTACTID.

VB.NET:
   Private Sub Binds()

        Me.txtContactContactID.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource1, "ContactID", True))
        Me.txtLastName1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource1, "LastName1", True))
        Me.txtManufacturer.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "Manufacturer", True))
        Me.txtDOM.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "DateManufacture", True))
        Me.txtSerialNumber.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "SerialNumber", True))
        Me.txtDEC.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "DateEscrow", True))
        Me.txtModelNumber.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "ModelNumber", True))
        Me.txtHUDNumber.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "HUDNumber", True))
        Me.txtUnitSizeA.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "UnitSizeA", True))
        Me.txtUnitSizeB.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "UnitSizeB", True))
        Me.rdoNewUnit.DataBindings.Add(New System.Windows.Forms.Binding("Checked", Me.BindingSource2, "New", True))
        Me.rdoUsedUnit.DataBindings.Add(New System.Windows.Forms.Binding("Checked", Me.BindingSource2, "Used", True))
        Me.txtFlooring.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "FlooringCompany", True))
        Me.txtSalesPerson.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "SalesPerson", True))
        Me.txtMisc.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "Misc", True))
        Me.txtComments.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "Comments", True))
        Me.txtFlooringAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "FlooringAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtLoanAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "LoanAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtInvoiceAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "InvoiceAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtSalesTaxAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "SalesTaxAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtFreightAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "FreightAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtHCDAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "HCDAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtDealerPackAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "DealerPackAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtEscrowAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "EscrowAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtAccessoriesAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "AccessoriesAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtFoundationAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "FoundationAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtSepticAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "SepticAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtAirConditioningAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "AirConditioningAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtSchoolTaxAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "SchoolTaxAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtSalesCommissionAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "SalesCommissionAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtMiscAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "MiscAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtProfitAmount.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "ProfitAmount", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "C2"))
        Me.txtPackageID.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "PackageID", True))
        Me.txtPackageContactID.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource2, "ContactID", True))
        Me.txtServiceContactID.DataBindings.Add(New System.Windows.Forms.Binding("text", Me.BindingSource3, "ContactID", True))
        Me.BindingNavigator1.BindingSource = Me.BindingSource2
        Me.BindingNavigator2.BindingSource = Me.BindingSource3
        Me.BindingNavigator3.BindingSource = Me.BindingSource1

    End Sub



    Private Sub frmNewRecord_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim CurrentRecord As Integer

        BindingSource1.DataSource = dsContact
        BindingSource1.DataMember = "Contact"
        BindingSource2.DataSource = dsPackage
        BindingSource2.DataMember = "Package"
       
        Binds()
    End Sub
 
Read the DW2 link in my signature, these sections:

Simple Data App - gives us a standard "Customers/Orders" scenario
Displaying Related Data - more detail on a related data such as yours

The key is the datarelation. It filters the child records to just those of the currently viewing parent. Note that you can ease the memory load on the client by loading only the child records you need (after loading parent records, for each record in parent, load all children with that parent.contactid)
 
yes, what cjard mentioned is right, u have to declare relationships between ur tables in ur dataset to achieve this..

By the way, u do not have to code them like what u are doing, it sure looks like a mess and hard to maintain, when u look in your datasource explorer, u can expand the tables and drag and drop the fields of your table into your form. Right click on the field and u can choose textbox, combo box etc. etc.. and to get a table, u juz drag the entire table to your form.
 
By the way, u do not have to code them like what u are doing

Troy likes pain; you'll find tens of past posts from me to Troy saying a similar thing to what you mention here :)
 
Guys I can't drag my database, That creates it within my project and I want database independence. I allow my program to select the location of which database to use. This means more code, and sometimes binding is not an option. I can create Add routines that allow for me to add my data into the tables just fine generating proper ID's which. I've constructed relationships inside my database with topics that are similar in the different tables.
I was able to bind my binding Navigator controls just fine to my tables and the data I want them to navigate through with the exception that I only want certain ones that are under the same ID's as each other.

From my pervious posts I've stated I have three tables inside my database.

Contact

Package

Service

Contact has a field named ContactID inside it as the primary Key and is autogenerated.

Package has a field named ContactID inside it as well but is not autogenerated it is assigned when you create a record for the Contact and it is assigned that ContactID. PackageID is autogenerated and assigned to each package created for each Contact.

So in theory they should be organsized just fine and they are.

but when I bind a BindingSource to my Table (Datasource = dsPackage, DataMember = Package), and then a Binding Navigation control to that Binding Source (BindingSource = Bindingsource1); the binding Navigator scrolls though every entry in the table and I only want it to scroll throught the ones with a ContactID matching the ContactID of the Contact Table related to the Package.
 
Guys I can't drag my database, That creates it within my project and I want database independence.
I keep telling you that's doable too

I allow my program to select the location of which database to use. This means more code,

Yup, about 2 lines more! :) You dont seem to mind writing more lines of code though, so I'm a bit flummoxed

and sometimes binding is not an option.
Well, yeah, that's true.. but there's nothing dictating that you use binding with the New Way.. you really can do it all manually if you want. The key point is that doing stuff New Way makes your program much better structured, faster to write good data access code and removes a lot of headache and complication from your button handlers; complication that other coders have to wade through when you hit a bump..

I can create Add routines that allow for me to add my data into the tables just fine generating proper ID's which.
Unexpected end of sentence

I've constructed relationships inside my database with topics that are similar in the different tables.
I was able to bind my binding Navigator controls just fine to my tables and the data I want them to navigate through with the exception that I only want certain ones that are under the same ID's as each other.
Database relationships have no effect or bearing on client side relationships


but when I bind a BindingSource to my Table (Datasource = dsPackage, DataMember = Package), and then a Binding Navigation control to that Binding Source (BindingSource = Bindingsource1); the binding Navigator scrolls though every entry in the table and I only want it to scroll throught the ones with a ContactID matching the ContactID of the Contact Table related to the Package.

Read the DW2 link in my signature, section on "Displaying Related Data"Dont worry.. it wont force you to convert to the voodoo of New Way, but you will find the answer to your question there, and it is perfectly compatible with Old Way
 
OMG roflmao .... You know I don't ignore you I do read those links I'm just not seeing what your referring too. I'm not an idiot although relearning the entire way I've taught myself programming is a bit difficult. Everything I've learned is self taught by books. I'm sorry if I'm slow understanding what you're referring too.

That said I really do appreciate your aid. But with me patience is a virtue. What I don't get is how my code is working fine with the exception of a couple of things. And using your way will add twice as much code Split my brain in two, causing me a massive brain hemmorage, and could cause my entire world to crumble around me.

I don't really consider myself an ignorant man, but sometimes it just appears that way.

As far as structure, I don't have to worry about other programmers, I've always been a solo programmer. At my age there are no jobs wanting self taught computer programmers with no experience. This is for my own benefit.

That said I have learned quite a bit from reading your links, but not enough evidentally. Pain is not what I'm after it just seems to follow me. It's the old addage, "You can't teach an old dog new tricks". Well it's not because the old dog doesn't want to learn it's because the new tricks are confusing to the old dogs previous learned behavior.
 
OMG roflmao .... You know I don't ignore you I do read those links I'm just not seeing what your referring too. I'm not an idiot although relearning the entire way I've taught myself programming is a bit difficult. Everything I've learned is self taught by books. I'm sorry if I'm slow understanding what you're referring too.

Er.. the section on related data. See, it works like this:

You ahve a data set, with at least 2 datatables and one relation
Then you put some controls on a form and they bind through the parent binding source, to the datatable. Then you put some controls on the form and they bind to the child bindingsource, but here;s the kicker.. the source of data for the child is NOT the datatable, but the relation exposed by the parent object.
You fill both datatables with related records and then whatever parent is on show, the children are filterd to be only those of that parent.

It's Not Rocket Science

The "Simple Data App" section shows you this behaviour too, and I can follow that example in about 1 and a half minutes, and end up with a working app that shows, edits and saves related data. 5 lines of code. 1.5 minutes.

Your code is hundreds of lines long and took you hours. How is it possible that what I'm teaching will double your code? It's 5 lines! It takes me longer to write posts to you than it would to code that

I don't really consider myself an ignorant man, but sometimes it just appears that way.
I was considering.. erm.. "traditional"

[quote[
As far as structure, I don't have to worry about other programmers,[/quote]
Doesnt matter. You'll return to your own code in 3 months and go "WTF.. ?"
If keeping your zone a mess is a philosophy you apply to all aspects of your life.. well.. sure wouldnt like to be round your place for beers on friday..

End of the day, youre gonna hit a bump with your code. Someone else is gonna have to read it. This isnt one man 100% of the time. Code for others and you'll like reading what you wrote. Code as if it dont matter because only you will see it and you wont even wanna see it yourself


That said I have learned quite a bit from reading your links, but not enough evidentally.
Those links wont teach you how to conenct to different databases, dont look for it. They will teach you how to display related data
 
Back
Top