Let's say, we have these SQL tables:
[Articles]
bill int (pkey)
arti int (pkey)
name varchar(50)
[Bills]
bill int (pkey)
fdate date
uid int
Let's suppose we have a list of items on a grid, representing a bill:
--------------------------------------------------------------
Id[ 15] Date [01-01-1980]
User [pepe]
Code Name
----------------------------
1 Something
2 Article name
3 lolololololoolo
4 datadatdatdatdata
5 datadatdatdatdata
--------------------------------------------------------------
So, we have a header with, an id, user, date, etc. And, then, the grid filled with items.
Both tables will be saved at the same time when the user decides (a save button). And, the user can also see a previous bill and modify it. So, what's better?
- Loop the items and make a query to decide: if exists is an INSERT, else, is an UPDATE.
- Delete All the items (by bill id) and then, do all INSERTS.