Summary
This article briefly introduces how to access the Oracle database using ASP. NET. First, it introduces the installation of components. Secondly, it briefly describes the core classes contained in system. Data. oracleclient. Finally, it explains the specific usage through an instance.
--------------------------------------------------------------------------------
Directory
Introduction
System requirements and Installation
Core categories
Example
References
--------------------------------------------------------------------------------
Introduction
Microsoft. NET Framework data provider for Oracle (. NET for Oracle) is a. NET Framework component. This component provides great convenience for us to access the Oracle database using. net. Developers who use. NET and Oracle are sure to be happy because they no longer need to use oledb that is not very "professional =" to access the Oracle database. This component is designed very similar to Microsoft. NET Framework data provider for SQL Server and oledb built in. net. If you are very familiar with these two built-in components, you may be familiar with learning this component.
The readers of this article mainly consider accessing the Oracle database using. NET technology.ProgramC # language, ADO. NET technology, and basic knowledge of Oracle Database are required. In this paper, some examples and comments are given based on ASP. NET technology. Of course, this does not mean that the. Net for Oracle component can only provide services for compiling ASP. NET programs. It can also provide convenience for Windows programs written using. NET technology.
This article briefly introduces ASP. NET for Oracle system requirements, installation and core classes, and then focuses on how to use this component to access the Oracle database. Including. Net for Oracle's access to special data types in a variety of Oracle databases, Introduction to the use of various core classes, andArticleFinally, an example is provided.
--------------------------------------------------------------------------------
System requirements and Installation
Before installing. Net for Oracle, you must first install. NET Framework Version 1.0. At the same time, make sure that the data access component is installed (MDAC 2.6 and later versions, recommended version is 2.7 ). To access the data in the Oracle database, you must install the Oracle 8i Release 3 (8.1.7) client and later versions. At present, Oracle9i has been released. The author installed Oracle 9i. All the programs in this article are compiled and debugged in the Oracle9i database environment.
The component installation is very convenient and runs oracle_net.msi directly. No setup is required during the installation process. Click "next =" to complete the installation. By default, a folder named oracleclient. net will be created under the c: \ Program Files \ Microsoft. NET Directory, which contains the following six files. The specific notes are as follows:
Note: The mtxoci8.dll file is not installed in the default folder, but in the system directory, for example, c: \ windows \ system32.
For developers, the system. Data. oracleclient. dll file is crucial. This is the core file of the. NET for Oracle component. During use, developers can install oracle_net.msi. net for Oracle component, the system will use this component as a default component of the system, just like the system we are familiar. data. sqlclient and system. data. the same is true for oledb components. However, it should be noted that when a developer finishes the program and delivers it to the user for use, for ease of use of the software, we do not want users to use the software before, install oracle_net.msi as a developer. At this time, developers can copy the system. Data. oracleclient. dll file to the bin directory of the software before publishing. In this way, you can use the functions provided by the software without installing oracle_net.msi. (This method is limited to developing programs that do not involve distributed transactions)
--------------------------------------------------------------------------------
Core categories
In the. NET for Oracle component, the namespace used for organizing classes and other types is system. Data. oracleclient. The namespace contains four core classes: oracleconnection, oraclecommand, oracledatareader, and oracledataadapter. If developers are familiar with the ADO. NET technology, they will be familiar with the use of these four classes. The content is very simple, and its usage is almost the same as sqlconnection, sqlcommand, sqldatareader, and sqldataadapter. We will not describe it in detail here. Readers will learn about the usage of these classes through examples later. Here we will only provide the following table for readers to briefly understand.
--------------------------------------------------------------------------------
Example
The following is an example of using the. NET for Oracle component to manipulate the Oracle database. Before writing a program, you must create a table in the Oracle database and add a row 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 row of data
"Insert into oracletypestable values ('test', 4, to_date ('2017-01-11
12:54:01 ', 'yyyy-mm-dd hh24: MI: ss'), '123 ')";
The following program accesses the Oracle database through the. Net for Oracle component and displays this line of data. In the program, pay attention to the classes described in the previous article, and think about how to use data processing classes in. net.
1. Using system;
2. Using system. Web;
3. Using system. Web. UI;
4. Using system. Web. UI. htmlcontrols;
5. Using system. Web. UI. webcontrols;
6. Using system. Data;
7. Using system. Data. oracleclient;
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 ;";
// Instantiate the oracleconnection object
13. oracleconnection conn = new oracleconnection (connstring );
14. Try
15 .{
16. Conn. open ();
// Instantiate the oraclecommand object
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 in the first column of the First row
21. oraclestring oraclestring1 = oracledatareader1.getoraclestring (0 );
22. response. Write ("oraclestring" + oraclestring1.tostring ());
// Read and display the data in the second column of the First row
23. oraclenumber oraclenumber1 = oracledatareader1.getoraclenumber (1 );
24. response. Write ("oraclenumber" + oraclenumber1.tostring ());
// Read and display the data in the third column of the first row
25. oracledatetime oracledatetime1 = oracledatareader1.getoracledatetime (2 );
26. response. Write ("oracledatetime" + oracledatetime1.tostring ());
// Read and display the data in 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 .{
// Exception Handling
40. Message. Text = ee. message;
41 .}
42. Finally
43 .{
// Close the connection
44. Conn. Close ();
45 .}
46 .}
47 .}
If you are familiar with the data operations in. net, I believe the above program is completely understandable. So here we will analyze the aboveCodeIt does not make much sense.
Remember that the. Net for Oracle component is designed like the data provider for SQL Server and oledb built in. net.
Http://www.wrclub.net/study/listarticle.aspx? Id = 1344