Board index » cppbuilder » autoinc in MS SQL 2000

autoinc in MS SQL 2000


2004-06-24 08:29:15 PM
cppbuilder89
trying to understand MS SQL autoinc
I do the following
create Table Data (
[RecNumber] [int] IDENTITY(1,1),
ItemNumber Char(30),
ItemDescription Char(60)
Primary key(RecNumber))
when inserting new records into the table how do I get the recnumber to auto
increment???
here is what I am doing so far
Query2->Close();
Query2->SQL->Clear();
Query2->SQL->Add("select * from LabData");
Query2->Open();
while(!Query2->Eof)
{
ADOTable2->TableName="Data";
ADOTable2->Open();
ADOTable2->Last();
ADOTable2->Insert();
ADOTable2->FieldByName("ItemNumber")->AsString =
Query2->FieldByName("Itm_NO")->AsString;
ADOTable2->Next();
}
 
 

Re:autoinc in MS SQL 2000

James Peterson wrote:
Quote
trying to understand MS SQL autoinc

I do the following
create Table Data (

[RecNumber] [int] IDENTITY(1,1),

Does [RecNumber] allow NULLs? RecNumber should be generated when it is
set to NULL.
Quote
ItemNumber Char(30),

ItemDescription Char(60)

Primary key(RecNumber))

when inserting new records into the table how do I get the recnumber to auto
increment???

here is what I am doing so far

Query2->Close();
Query2->SQL->Clear();
Query2->SQL->Add("select * from LabData");
Query2->Open();
while(!Query2->Eof)
{
ADOTable2->TableName="Data";
ADOTable2->Open();
ADOTable2->Last();
ADOTable2->Insert();
ADOTable2->FieldByName("ItemNumber")->AsString =
Query2->FieldByName("Itm_NO")->AsString;

ADOTable2->Post();
Quote
ADOTable2->Next();
Should this be: Query2->Next();
Quote

}