Method for connecting Oracle Databases with ASP.NET (C #)

xiaoxiao2021-03-06  65

I saw ASP.NET to connect to Oracle today.

The method of the database is obtained by the following code. This code opened myTable table and listed the operator's name. The field type is ORACLESTRING. When reading is a field number, I don't know how to use the field name to read the contents of a certain field. Below is the code:

// First add two references

Using system.data.oraclient;

Using system.data;

// Add a button on the form, called Button1, double-click Button1, enter the following code private void button1_click (object sender, system.eventargs e) {string connectionString = "data source = sky; user = system; password = manager;" ; // Write the connection string OracleConnection conn = new oracleConnection (Connectionstring); // Create a new connection try {conn.open (); OracleCommand cmd = conn.createCommand ();

cmd.comMandtext = "Select * from myTable"; // Write SQL statement OracleDataRead Odr = cmd.executeReader (); // Create an OracleDateReader object while (Odr.Read ()) // read data if ODR. Read () returns to false, explains the end of the recordset {response.write (odr.getroraclestring (1) .tostring ()); // Output field 1, this number is the field index, how to use the field name Still need to be studied} Odr.close ();} catch (exception ee) {response.write (Ee.Message); // If there is an error, output error message} finally {conn.close (); // Close connection}}

The entire program is not very complicated, but it is also enough for me to study for a long time. After all, the ASP.NET and ASP have VB differences. Slowly learn.

Source is blog.9cbs.net/lh8287, author iWorm

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

New Post(0)