Results 1 to 12 of 12

Thread: Help Please??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154

    Help Please??

    hey Everyone...

    Here's what I need to do...

    Right now I have a button I click to create a new invoice...this works fine..then when the form closes and the invoice is new...it inserts all the rows in the datagrid into my sql server database...

    Now here's where I'm having problems.... If I edit an exsisting invoice...and add a new part to it....I need to also be able to insert into the database the newly added rows.....but I dont want to add the rows that were already added from the first time the invoice was created..otherwise there will be duplicates and primary key errors and so on...

    So how can I check to see if a row has been newly added to the datatable..... then go through and only add the rows that are new this time??

    Thanks in advance!!

  2. #2
    Lively Member flog3941's Avatar
    Join Date
    Nov 2002
    Posts
    123
    Im not sure I get what your doing.

    When you add a new invoice you create\add rows to a single table?

    If so why do you need multiple rows?

    Why not just one big row for each invoice?

    Please elaborate

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154
    I have a button...."New Invoice"....when I click this it opens up a new form for creating invoices......on this new form...there is a label that I click which opens another form with a list of all my parts displayed in a datagrid..

    When I click on the part from this form....it then adds it back to the invoice form where it is displayed in another datagrid.....

    I can add more than 1 part for each invoice...so I could have a invoice with 1 part..... up to say 100 or whatever...

    so when I close the invoice form it INSERTS into the sql server all the items(rows in datagrid)...

    once this form closes it displays another form which also contains a datagrid....this new form here displays all the invoices for that specific customer...

    So now....from this form....I can click on the exsisting invoices in the datagrid.... which opens the invoice form back up with the same items that were saved to the database...... this is where the problem arises..

    When I add a new part to an exsisting invoice....I dont want to RE_INSERT the items that are already in the database....so I need to somehow check if the newly added item is not already in the datagrid(database) from before??

    Let me know if you need anymore clarity...or maybe some screenshots or something..

    Thanks for the help

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154
    ***Bump***

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    In your datagrid, store the primary key (hidden column or use the primarykey field) for each item and when your form closes, you will know whether or not to issue an insert or update command.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154
    I'm not sure what you are saying...do you have an example of this or could you explain in a little more detail of what I have to do??

    Thanks

  7. #7
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872
    why don't you check if an record is already in your database (Select * from table where field1=fieldFromDatagrid) if a value is returned, just update, else add new record.
    - Use the thread tools to Mark your Thread as Resolved when your question is answered.
    - Please Rate my answers if they where helpful.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154
    There can be more than 2 items in the datagrid....

    so if I use the method you suggested...then how will I be able to tell it to do that for all the records...not just one??

  9. #9
    Lively Member
    Join Date
    Jan 2003
    Posts
    69
    Hi how does the rows save before you click on new invoice,
    is a temp or the database just read back to that place and make shure the item isn't there.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154
    When a new invoice form closes.........it inserts the items from the datagrid into the database...

    So it updates/Inserts from the invoice form closing....

  11. #11
    Lively Member
    Join Date
    Jan 2003
    Posts
    69
    So if i get it correct the user enters the same item it should check the database if there is the item give him a msgbox,

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154
    Sorry I was clear on what you meant...

    Here's what happens..

    The user clicks "new invoice"...this opens the invoice form...

    then the user clicks "add new part"...this opens the parts form...

    Then the user clicks on the part in the datagrid of the parts form to add the part to the invoice form...( so far there is no updating to the database..)

    so then if the user adds the same part...in the same invoice...it just increases the QTY from 1 to 2..and so on...

    Got it now?

    Thanks again

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