Click here to Skip to main content
15,877,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to write network program for store
i have two tables

SQL
TblSellDocument
IDDocSell	int	Unchecked key and IDentity
IDAccount	int	Unchecked
IDOC	int	Unchecked
IDUser	int	Unchecked
IDCustomer	int	Unchecked
Datein	datetime	Unchecked
SumPrice	bigint	Unchecked
Status	bit	Unchecked 

TblSellProduct
IDsell	int	Unchecked key and IDentity
IDDocSell	int	Unchecked foreign key
IDStuff	int	Unchecked
Number	int	Unchecked
SellPrice	bigint	Unchecked
Discount	bigint	Unchecked
SellMultiplePrice	bigint	Unchecked 


now i want design a form for insert data but when i want fill TblSellProduct i don't know how can I find TblSellDocument.IDDocSell
IDDocSell must unused with other users
I'm so confuse
this way is correct or not ?
Posted

Are you using SQL server: if so you can set Identity Specification to auto increment when new rows are inserted. Other databases have similar features. Otherwise you'd need to use a 'select distinct' query to get a list of used IDs.
In the form, you can leave ID blank until it has been created or can you put the next available ID.
 
Share this answer
 
Comments
aref.bozorgmehr 11-Aug-13 23:32pm    
yes i use sql and my ID field is Identity
but my problem is when i insert data
look at this
insert into TblSellDocument(...) value(...)
insert into TblSellProduct(IDDocSell) value(?)
?=> where can i find TblSellDocument.IDDocSell in last insert
If there is no auto increment of DocSell, try using MAX + 1 formula to increment the value
 
Share this answer
 
Comments
aref.bozorgmehr 12-Aug-13 2:13am    
we can't because maybe max+1 use with another user
Gauri Chodanker 12-Aug-13 2:25am    
Does that mean you already have the ID's with you, for which User may or maynot exists..
Well in this case why don't you try this

SELECT MIN(IDDocSell)
FROM TblSellDocument
WHERE IDUser IS NULL
@@IDENTITY

It returns the last identity value generated for any table in the current session, across all scopes.

Let me explain this... suppose we create an insert trigger on table which inserts a row in another table with generate an identity column, then @@IDENTITY returns that identity record which is created by trigger.
SCOPE_IDENTITY

It returns the last identity value generated for any table in the current session and the current scope.

Let me explain this... suppose we create an insert trigger on table which inserts a row in another table with generate an identity column, then SCOPE_IDENTITY result is not affected but if a trigger or a user defined function is affected on the same table that produced the value returns that identity record then SCOPE_IDENTITY returns that identity record which is created by trigger or a user defined function.
IDENT_CURRENT

It returns the last identity value generated for a specific table in any session and any scope.

In other words, we can say it is not affected by scope and session, it only depends on a particular table and returns that table related identity value which is generated in any session or scope.

source^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900