SELECT @ @IDENTITY in Access

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.