|
Subject:
|
Inserting a Value into an SQL Identity Field in VB
|
|
Posted By:
|
vbmazza
|
Post Date:
|
4/27/2005 7:54:46 AM
|
I am using Visual Basic .Net to insert values into an SQL Database.
One of the fields I have is an Identity Field, the purpose of this field in my database is to have a number that increments by 1 each time a record is entered.
The problem is that I don't know what value to use in my INSERT INTO command to do this. Because I am new to this, my understanding of the Identity field was that it automatically incremented the value in that field each time a new record was inserted, if this is not the case can someone help me with this.
Basically I have a field called ReportID, I am inserting a date and a name into this database and I want it to auto-generate the ReportID number to increment by 1 each time a record is entered. Bearing in mind the each value is stored in a string or date variable.
I am pulling my hair out, so any help would be great!
VBMazza
|
|
Reply By:
|
BrianWren
|
Reply Date:
|
4/27/2005 2:45:47 PM
|
Your database should be set up so that there is a trigger before insertion. That trigger should get the next value from a sequence that has been set up for this table. When the value is retrieved fram a sequence, the sequence is automatically incremented.
The Before Insert trigger should fill in the value.
(BTW: the trigger should do all of this only if the record is a new record...)
|