Results 1 to 9 of 9

Thread: Adding multiple items to one Invoice

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    131

    Adding multiple items to one Invoice

    Any ideas on how to add multiple items or transactions to one Invoice No? I do not have the Invoice No set as the primary key in the database because when I went to add a second line onto the invoice it says that I can not have a dup key, so I made the line no the primary key. But, I have to rig it to accept it. (See code). Also, the invoice no is always saying -1, how can I get the number to change so that I may finish this program.

    Code:
    Try
                Me.InvoicesBindingSource.EndEdit()
                Me.InvoicesTableAdapter.Update(Me.CloseoutsDataSet.Invoices)
                InvoicesBindingSource.AddNew()
                InvoiceNoTextBox.Text = Label1.Text
            Catch ex As Exception
                MessageBox.Show("No New Line Has Been Entered!")
            End Try
    See? I have to rig it, but like I said, the Invoice No is not updating, it is always being saved as (-1) which is ticking me off.

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Adding multiple items to one Invoice

    Usually in an invoicing system you have two tables - INVOICE HEADER and INVOICE DETAIL.

    The HEADER has a primary key of INVOICE NUMBER.

    The DETAIL can have a compound primary key - made of two fields - INVOICE NUMBER and LINE NUMBER.

    Any values that are common to all lines (like vendor maybe) go into the HEADER record.

    All values specific to a line go into the DETAIL record.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    131

    Re: Adding multiple items to one Invoice

    Ah, I see, and how does the detail header link to the header? I am new to Relations? Is there a GUI way to do it rather then programmatically?

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Adding multiple items to one Invoice

    The linking is through the fact that the invoice number is common between the "parent" header row and the "child" detail rows.

    We don't use bound controls - so I'm unsure how to get multiple rows added with that method.

    What is your backend database?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    131

    Re: Adding multiple items to one Invoice

    Local Dataset (.sdf) is our back end database.

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Adding multiple items to one Invoice

    That's MS SQL CE (compact edition) by the SDF extension you mention.

    There are many limitations to CE - we use it for Pocket PC apps.

    We don't do this - but I believe you can create and manage the database, tables and schema from within Visual Studio.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    131

    Re: Adding multiple items to one Invoice

    Yes, I am aware of that, however, how would I update both Header and Details so that each table will reflect the information? I don't want Invoice No 1 (example) to reflect the details of Invoice No 2.

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Adding multiple items to one Invoice

    We don't use bound controls here.

    We would do:

    Code:
    Insert into InvHeader values (1,'abc',...)
    And based on the success of that insert we would

    Code:
    Insert into InvDetail values (1,1,...)
    Insert into InvDetail values (1,2,...)
    One insert for each line.

    We "code" all our SQL statements - INSERT's, UPDATE's and DELETE's based on what the user is doing in the GUI.

    For SELECT's we would

    Code:
    Select x,y,z From InvHeader Left Join InvDetail on InvDetail.InvNo=InvHeader.InvNo
    Again - I'm not familiar with bound controls so you'll have to wait for someone else to come along with more info.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    131

    Re: Adding multiple items to one Invoice

    How come when I Add an Invoice the Invoice No is "-1" even when save is pressed? How do I fix that?

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