Hi all,
Is there anyway to increase a field reapitedly? I meam, say we have a blabnk field and we want to increase all the fields by 1 so the first field will be =1, second =2 thired =3 and so on.
Thanks in advance
Printable View
Hi all,
Is there anyway to increase a field reapitedly? I meam, say we have a blabnk field and we want to increase all the fields by 1 so the first field will be =1, second =2 thired =3 and so on.
Thanks in advance
I do not know what you want to do. Are you talking about field names or sizes, values or what?
values, as I mentiond, If The firat field is 1 the same field in the second record becomes 2 and so on
I Hope I'm clear,
If using MS ACCESS put the Field property to AUTONUMBER!
How do I do that?
1) OPEN MS ACCESS
2) SELECT YOUR TABLE
3) PRESS DESIGN BUTTON ON THE RIGHT HAND SIDE
4) CHANGE THE DATATYPE OF YOUR DESIRED FIELD TO SUTONUMBER
5) SAVE YOUR DATABASE
6) CLOSE IT
THATS IT :d
KINJAL
If you are using oracle look up sequences they accomplish the same as autonumber in MSAccess
intRecNum = select sequencename.next from dual;
will give you the next sequence number.
I am sure tha sql server has an appropriate routine to do that also.
The danger of using sequences is that if you ever lose your database content and restore it all sequences will have to be reset to that largest value that it contained at the time of failure.
Another way to do it would be to create your own class and a db table tblSeqVal and keep a number in it. You can create methods .next, .first, .last, etc and then go to your
own "autonumber or sequencer. That way if you db crashes the restore will also restore your sequence table.
Table definition
create table tblSeqVal as (
intSeqField number(5));
next could be
define sequence table class
Public Function next () As Integer
db definition/connection stuff
intRecNum = select max(intSeqField + 1) from tblSeqVal;
End Function
Hope this helps
Regards
Sorry, I must have mentiond that in advance, I am using MS jet engine through VB
JET ENGINE! Then my method will work out perfectly!
Thanks but How do I do it from inside a program?
Just don't provide a value for that field when inserting a new record. The DB will value it automatically.
:)