I have this probelm
In table of my SQL database I have column which should contain text, which
contains the ID of the row in Dataset.
My table has this columns
ID
Date
Time
UniqueID
Status
..... etc.
I want the column UniqueID to contain the ID of the row and some text, like
"ABC000" where the 000 is ID of the row. Also every new row, inserted in
the table has ID which lenght is variable. The first row has ID 1 and
lenght1, the 12th row has ID 12 and lenght of the ID 2.
I want may UniqueID to be with speciefied lenght of 8 chars, so some leading
zeroes should be inserted. The final result should be "ABC00012" for the
12th row.
The UniqueID filed in my table can't be NULL.
So when I add new row to a table, somehow I should know what will be its ID.
I can determine it in dataset, it is +1 of the rows count in dataset, but
when it's commited to the database, it may get new ID. I made a Stored
procedure, which puts a temporary value in UniqueID column, add new row to
table with this temp value, then reads row ID and makes modification of
UniqueID column, by replacing it with the generated value from the real ID.
This works fine.
The main problem is, how to generate this UniqueID in the moment that user
adds a new row to dataset.
My app look something like this. There is a readonly datagrid, binded to
dataset and some buttons like "Add record", "Remove record" and etc. When
user clicks on the "Add record" button, a new form loads, where user can
enter the needed information. This windows is the place, where I need to
show the user this UniqueID, but it does not exist at this time, because the
row is not in the database yet. Like I said, I may generate it from the
current count of the rows in dataset, but it may differ when commited to
database.
Any ideas?