Does the SELECT @ @identity exist in the Access database? The answer is yes. However, access can execute only one SQL at a time, and multiple SQL needs to be executed multiple times, which is a limitation. In SQL Server, you can execute more than one SQL statement at a time. Access uses T-SQL for Jet-sql,sql server, which differs greatly in usage.
However, in Access, you can execute N statements in succession, as follows:
Cmd.commandtext = "INSERT into MyTable (n1,n2) VALUES (22,11)";
int count = cmd. ExecuteNonQuery ();
Cmd.commandtext = "SELECT @ @IDENTITY";
int newId = (int) cmd. ExecuteScalar ();
Where the SELECT @ @IDENTITY is the auto-numbered keyword to remove the previous statement.
You can use ExecuteReader () to execute several SQL statements at the same time in SQL Server
PetShop 4.0 has the following usage:
using (SqlDataReader rdr = cmd. ExecuteReader (commandbehavior.closeconnection)) {
Read the returned @ERR
Rdr. Read ();
If the error count is not zero to throw an exception
if (RDR. GetInt32 (1)! = 0)
throw new ApplicationException ("DATA INTEGRITY ERROR on ORDER insert-rollback ISSUED");
}
The SQL statements for the CMD object are as follows (which I took out in debugging):
Declare @ID int;
Declare @ERR int;
INSERT into Orders VALUES
(@UserId, @Date, @ShipAddress1, @ShipAddress2, @ShipCity, @ShipState, @ShipZip, @ShipCountry, @BillAddress1, @ BillAddress2, @BillCity, @BillState, @BillZip, @BillCountry, ' UPS ', @Total, @BillFirstName, @BillLastName, @ Shipfirstname, @ShipLastName, @AuthorizationNumber, ' us_en ');
SELECT @[email protected] @IDENTITY;
INSERT into Orderstatus VALUES (@ID, @ID, GetDate (), ' P ');
SELECT @[email protected] @ERROR;
INSERT into LineItem VALUES (@ID, @LineNumber0, @ItemId0, @Quantity0, @Price0);
SELECT @[email Protected][email protected] @ERROR;
INSERT into LineItem VALUES (@ID, @LineNumber1, @ItemId1, @Quantity1, @Price1);
SELECT @[email Protected][email protected] @ERROR;
SELECT @ID, @ERR
SELECT @ @IDENTITY in Access