In. Using Oracle database transactions in net

Source: Internet
Author: User
Tags insert integer oracle database
oracle| Data | Database In this article, you will learn how to use database transactions in Visual Basic. NET (vb.net) and Visual C #. NET (C #). Specifically, you will learn about database transactions, the use of OracleTransaction objects in. NET programs, and how to set up transaction savepoint. All of the scripts and files referenced in this article are available here. This article assumes that you are generally familiar with C # and vb.net programming.

The required software

If you want to follow us step-by-step through the examples given in this article, you need to install the following software:

Windows NT 4.0, Windows 2000, Windows XP Professional, or Windows Server 2003

Access to an installed Oracle database (Oracle8i version 3 8.1.7 or later)

Oracle Client (version 10.1.0.2.0 or later)

Oracle Net (version 10.1.0.2.0 or later)

Oracle Data Providers for. NET (version 10.1.0.2.0 or later)

Microsoft. NET Framework (version 1.0 or later)

Microsoft. NET Framework SDK (version 1.0 or later)

If you plan to use an enterprise service transaction or a distributed transaction to develop and run your application, you will also need to install Oracle services for Microsoft Transaction Server (10.1.0.2.0 or later).

You need to download and install the. NET Framework and SDK separately (install the framework first). You also need to download and install Oracle database 10g, which includes Oracle data Provider for. NET (odp.net). You can choose to install Odp.net and database servers on different computers or on the same computer.

Note: The odp.net drivers are optimized for Oracle database access, so they can achieve optimal performance, and they also support the rich features of Oracle databases, such as BFILE, BLOBs, CLOB, XmlType, and so on. If you are developing a. NET application that is based on an Oracle database, Odp.net is undoubtedly the best choice in terms of features and performance.

Database schema Settings

First, you need to set up the database schema, where we use a simplified example of a Web store. You must first create a user named store and grant the required permissions to the user in the following manner (you must first log on to the database as a user with create user rights to create a user):

CREATE USER store identified by store;
GRANT Connect, resource to store;

Note: You will find the first two statements and other statements in this section that set up the store mode in the source code file Db1.sql.

The following statement is connected as a store user:

CONNECT Store/store;

The following statement creates the required two database tables, named Product_types and Products:

CREATE TABLE Product_types (
product_type_id INTEGER
CONSTRAINT product_types_pk PRIMARY KEY,
Name VARCHAR2 (Ten) not NULL
);

CREATE TABLE Products (
product_id INTEGER
CONSTRAINT products_pk PRIMARY KEY,
product_type_id INTEGER
CONSTRAINT Products_fk_product_types
REFERENCES product_types (product_type_id),
Name VARCHAR2 not NULL,
Description VARCHAR2 (50),
Price Number (5, 2)
);

Note: If you create these database tables for store users in a different mode, you will need to modify the schema names in the sample configuration file (which you will see later).

Table product_types is used to store the name of a product type that the sample online store might inventory, and the table products contains details of the product being sold.

The following INSERT statement adds rows to the table product_types and products:

INSERT into Product_types (
PRODUCT_TYPE_ID, Name
) VALUES (
1, ' book '
);
INSERT into Product_types (
PRODUCT_TYPE_ID, Name
) VALUES (
2, ' DVD '
);

INSERT into the products (
product_id, product_type_id, name, description, price
) VALUES (
1, 1, ' modern ', ' A description of Modern science ', 19.95
);
INSERT into the products (
product_id, product_type_id, name, description, price
) VALUES (
2, 1, ' chemistry ', ' Introduction to Chemistry ', 30.00
);
INSERT into the products (
product_id, product_type_id, name, description, price
) VALUES (
3, 2, ' Supernova ', ' A star explodes ', 25.99
);
INSERT into the products (
product_id, product_type_id, name, description, price
) VALUES (
4, 2, ' Tank war ', ' Action movie about a future war ', 13.95
);

COMMIT;

Next, you will learn about the contents of the database transaction.

[1] [2] [3] Next page



Related Article

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.