Abstract This paper briefly describes how to use ASP.NET access to 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. Introduction Microsoft .NET Framework Data Provider for Oracle (hereinafter referred to as .NET for Oracle) is a component .NET Framework. 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 must be installed 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 named OracleClient.net in the C: / Program files / microsoft.net directory, which contains the following six files, and the specific comments are as follows: Note: MTXoci8.dll file is not installed by default In the folder, it 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 of the program that does not involve distributed transactions) Core. Introduction. Net for organizational classes and other types of namespaces 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, the following 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. OracleTypesTable establish a table named "create table OracleTypesTable (MyVarchar2 varchar2 (3000), MyNumber number (28,4) Primary key, MyDate date, MyRaw RAW (255))"; insert a row "insert into OracleTypesTable values ( 'test ', 4, to_date (' 2000-01-1112: 54: 01 ',' YYYY-MM-DD HH24: MI: SS '),' 0001020304 ') "; The following program is to pass the .NET for Oracle component Access the Oracle database and display this line of data. Please note the classes illustrated in the procedure, and the method of use of the data processing class in Lenovo .NET.
1.Using system; 2.using system.Web; 3.using system.web.ui.htmlcontrols; 5.using system.web.ui.webcontrols; 6.using 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. {// Setting connection string 12. String Connstring = " Data Source = EIMS; User = ZBMIS; Password = zbmis; "ortho-instantiated OracleConnection object 13. OracleConnection conn = new oracleConnection (ConnString); 14. Try15. {16. Conn.open (); // Instantiate 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 of the first line of the first line 21. ORACLESTRING ORACLESTRING1 = ORACLEDATAREADER1.GETORACLESTRING (0); 22. Response.write ("ORACLESTRING" ORACLESTRING1.TOSTRING ()); // Read Take 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 Data of the third column 25. OracleDatetime OracleDateTime1 = OracleDataReader1.GetOracleDateTime (2); 26. Response.write ("OracleDateTime" () ORACLATETIME1.TOSTRING ()); // Read and display the fourth column of the first row of data 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.} // Release resource 36. OracleDataReader1.close (); 37.} 38. Catch (Exception EE) 39. {// Exception Process 40. Message.Text = Ee.Message; 41.} 42. Finally43. {// Close connection 44. Conn.close (); 45.} 46.} 47.} If you are familiar with the content of data operation in .NET, then believe it The program is fully understood. So the analysis here is not very large.