Introduction to access the Oracle database using ASP.NET

zhaozj2021-02-12  182

Summary

This paper briefly describes how to use ASP.NET to access Oracle databases. First, the installation of the component is introduced; secondly, the core class included in System.Data.OracleClient; Finally, the specific method is explained by an instance.

-------------------------------------------------- ------------------------------

table of Contents

introduction

System requirements and installation

Core introduction

for example

Reference Information

-------------------------------------------------- ------------------------------

introduction

Microsoft .NET Framework Data Provider for Oracle (hereinafter referred to as .NET for Oracle) is a component .NET Framework component. This component provides great convenience for us .NET access Oracle database. Those developers who use .NET and Oracle, believe in happiness, because they don't have to use OLDB that is not very "professional =" to access the Oracle database. This component is designed very similar to the Microsoft .NET Framework Data Provider for SQL Server and OLEDB built in .NET. If the reader is very familiar with these two built-in components, I believe that you learn this component is also a light car.

The readers of this article are mainly written for programmers who use .NET technology to access Oracle databases, need to have certain C # languages, ADO.NET technology, and Oracle database basics. The disclosure of which is combined with ASP.NET technology and specific annotations. Of course, this does not mean that .NET for Oracle components can only provide services for writing ASP.NET programs, and it can also provide convenience for Windows programs written using .NET technology.

This article briefly introduces the system requirements and installations and core classes of ASP.NET for Oracle, followed by the key to access the Oracle database using this component. This includes .NET for Oracle Access to special data types in a variety of Oracle databases, introduction of various core types, and in the final example of the article, etc.

-------------------------------------------------- ------------------------------

System requirements and installation

Before installing .NET for Oracle, you must first install .NET Framework Version 1.0. At the same time, it is also necessary to determine the installed data access component (MDAC 2.6 and above, the recommended version is 2.7). Since it is necessary to access the Oracle database, then you need to install Oracle 8i Release 3 (8.1.7) Client and the above version. At present, Oracle9i has been released, the author is installed in Oracle 9i, all the procedures in this article are written and debugged in the Oracle9i database environment.

The installation of the component is very convenient, running Oracle_Net.msi directly. No settings are required during the installation process, all the way to click "Next =" to complete the installation. The default installation will create a folder called OracleClient.net in the C: / Program Files / Microsoft.net directory, which contains the following six files, and the specific annotations are as follows:

Note: The MTXoci8.dll file is not installed in the default folder, but is installed in the system directory, for example: C: / Windows / System32 directory.

For developers, it is critical to the System.Data.OracleClient.dll file. This is the core file of the .NET for Oracle component. During use, developers can use the .NET for Oracle component by installing Oracle_Net.msi, when using this component as a system default component, as if it is system.data.sqlclient and system. Data.OleDB components are the same. However, it is necessary to pay attention to: When the developer is divided into the user after the program has completed the program, we do not want to install Oracle_Net just like developers before the user uses this software. . At this time, the developer can copy the system.data.OracleClient.dll file to the BIN directory of the software before publishing. This way users can use the functionality provided by the software without the need to install Oracle_Net.msi. (This method is limited to the development procedures do not involve distributed transactions) ------------------------------------ --------------------------------------------

Core introduction

The .NET for Oracle component is used for organizational classes and other types of names for organizational classes and other types of spaces are System.Data.OracleClient. In this name space, it mainly contains four core classes, which are: OracleConnection, OracleCommand, OracleDataRead, OracleDataAdapter. If the developer knows ADO.NET technology, the use of these four classes will be familiar. These content is very simple, and the specific use is almost the same as SqlConnection, SqlCommand, SqlDataReader, SqlDataAdapter. This is no longer detailed, the reader will learn about the use of these classes in the following manner, and only the following table is given to readers.

-------------------------------------------------- ------------------------------

for example

Below is an example of manipulating an Oracle database using the .NET for Oracle component. Before writing the program, you must create a table in the Oracle database and join a line of data. Use the following statement.

Create a table named Oracletypestable

"Create Table ORACletYpestable (Myvarchar2 Varchar2 (3000), MyNumber Number (28, 4)

Primary Key, MyDate Date, MyRAW RAW (255)) ";

Insert a line of data

"INSERT INTO ORACLETABLE VALUES ('Test', 4, TO_DATE ('2000-01-11

12:54:01 ',' YYYY-MM-DD HH24: MI: SS '),' 0001020304 ') ";

The following program is to access the Oracle database through the .NET for Oracle component, and display this row data. Please note the classes illustrated in the procedure, and the method of use of the data processing class in Lenovo .NET.

Using system;

2.using system.Web;

3.USING System.Web.ui;

4.USING System.Web.ui.htmlControls;

5.using system.Web.ui.WebControls;

6. JOSING SYSTEM.DATA;

7.using system.data.racleClient; 8.public class pic2: Page {

9. Public Label Message;

10. Public void Page_Load (Object Sender, Eventargs E)

11. {

/ / Set the connection string

12. String connString = "Data Source = EIMS; user = zbmis; password = zbmis;";

// Institute instantiate OracleConnection objects

13. OracleConnection Conn = New OracleConnection (ConnString);

14. TRY

15. {

16. conn.open ();

// Instantiate OracleCommand objects

17. OracleCommand cmd = conn.createCommand ();

18. cmd.commandtext = "Select * from zbmis.oracletypestable";

19. OracleDataReader OracleDataReader1 = cmd.executeReader ();

// read data

20. While (OracleDataReader1.Read ()) {

// Read and display the data of the first line of the first line

21. Oraclestring Oraclestring1 = OracleDataReader1.Getoraclestring (0);

22. Response.write ("ORACLESTRING" ORACLESTRING1.TOSTRING ());

// read and display the data of the second column of the first line

23. OracleNumber OracleNumber1 = OracleDataReader1.GetoracleNumber (1);

24. Response.write ("OracleNumber" ORACLENUMBER1.TOSTRING ());

// Read and display the data of the third column of the first line

25. OracleDateTime OracleDateTime1 = OracleDataReader1.GetOracleDateTime (2);

26. Response.write ("OracleDateTime" OracledateTime1.toString ());

// read and display the data of the fourth column of the first row

27. Oraclebinary Oraclebinary1 = OracleDataReader1.Getoraclebinary (3);

28. IF (Oraclebinary1.isnull == False)

29. {

30. Foreach (Byte B in Oraclebinary1.Value)

31. {

32. Response.write ("byte" b.toString ());

33.}

34.}

35.}

/ / Release Resources

36. OracleDataReader1.close ();

37.}

38. Catch (Exception EE) 39. {

// abnormal processing

40. Message.Text = EE.MESSAGE;

41.}

42. Finally

43. {

// Close connection

44. conn.close ();

45.}

46.}

47.}

If you are familiar with the contents of the data operation in .NET, then believe that the above program is fully understood. So the analysis here is not very large.

Please use the .NET and Oracle readers to remember: .NET for Oracle Components Design is very similar to the Built-in Data Provider for SQL Server and OLEDB.

转载请注明原文地址:https://www.9cbs.com/read-7496.html

New Post(0)