Hi,
[quoted text, click to view] "pinarello" <pino@rello.com> wrote in message
news:pTK8f.7790$RL6.1864@blueberry.telenet-ops.be...
> Hi,
>
> I am creating a little invoicing application in C# on an access database.
> Main DB-structure: customers -> * invoice -> * invoicelines
> I created a typed dataset for it, (with xsd), including all constraints.
>
> I have an "invoice" screen, with:
> First section: Some customer fields, (read-only, because i arrive in the
> screen with customer allready selected).
> Second section: Some invoice fields.
> Third section: A invoice-lines datagrid.
>
> I would like to have the invoice-key as an only parameter for this screen.
>
> I created an instance of my dataset on this screen.
>
> I have a data-adapter for the customers table, of which I changed the
> select command to accept a parameter (customer key).
> I have a data-adapter for the invoices table, of which I changed the
> select command to accept a parameter (invoice key).
> I have a data-adapter for the invoicelines table, of which I changed the
> select command to accept a parameter (invoice key).
>
> Problem 1: When I use the invoice-data-adapter to fill my
> dataset.invoicetable, i get a constraint error (because the customer is
> not yet loaded in the dataset).
> Temporary solution: I have an extra parameter for my invoice screen that
> represents the customer key. (of which i would like to get rid of, because
> it is contained in the invoice),
> So I first load the customer, afterwards I load the invoice in the
> dataset. No constrain errors any more.
> Can anybody tell me how I can solve this in a better way, not by an extra
> parameter for the screen? (and not by not using constraints in my typed
> dataset)
You could also do something like:
- disable constraints
- load invoice, get customer_id from that
- load customer
- load invoice-lines
- enable constraints (will also check data already loaded)
Or you could do a query using Command.ExecuteScalar to get the customer_id
from the invoice_id.
[quoted text, click to view] >
> Problem 2: I use the invoice-lines-data-adapter to fill my
> dataset.invoicelinestable.
> This works fine, but when I insert a new line, the primary key used for
> that line, is not filled in with my access autonumber, but with one value
> higher than the highest key of the selected invoicelines.
> I have fixed it temporarly by filling my dataset.invoicelinestable without
> the invoice parameter, so all lines are loaded into my dataset, and then
> of course the highest number is correct. But I had to disable my
> constraints for this, because not all invoices (parents of the
> invoicelines) are loaded in my dataset. When I bound my datagrid to the
> foreign key between invoices and invoicelines, my datagrid contained only
> the appropriate invoicelines for that invoice. This solution doesn't seem
> to be very clean to me, because i don't like the idea of loading ALL my
> invoicelines into my dataset.
> Again, can this be solved in a better way, or is this the "only good" way
> to do it...?
For auto-generated key fields the key value of inserted rows is really
temporal, it's still the DB (or jet) that generates the actual key that will
be used and you can retrieve it during a DataAdapter.Update(...).
See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadonet/html/manidcrisis.asp
scroll to Microsoft Access/JET Issues, see RowUpdated eventhandler
HTH,
Greetings
[quoted text, click to view] >
> Thanks in advance,
> Steven.
>
>