Asp tutorial. net c connect to oracle database tutorial and display data
This section is a connection between the asp.net tutorial and the oracle database, and displays all the data in the data.
Data source = torcl; user id = myusername; password = mypassword;
Data source = (description = (address_list = (address = (protocol = tcp) (host = myhost) (port = myport) (connect_data = (server = dedicated) (service_name = myoraclesid); user id = myusername; password = mypassword;
Oracle client
Tnsnames. ora
List <per> lp = new list <per> ();
String SQL = "select * from man ";
Try
{
Orc. open ();
Oraclecommand cmd = new oraclecommand (SQL, orc );
Oracledatareader odr = cmd.exe cutereader ();
While (odr. read ())
{
Per p = new per ();
P. id = (int) odr ["id"];
P. name = (string) odr ["name"];
P. sex = (string) odr ["sex"];
P. age = (int) odr ["age"];
P. address = (string) odr ["address"];
Lp. add (p );
Odr. close ();
}
Return lp;
}
Catch (exception e)
{
Console. writeline ("error! The reason is: "+ e. message );
Return null;
}
Finally
{
Orc. close ();
}