1. Import Reference System.Data.OracleClient.dll file
2, in the head using System.Data.OracleClient;
To read data through a dataset:
To create a connection to a database
OracleConnection oracon=new oracleconnection ("User Id=112;data source=wmatech;password=112");
Create a new DataAdapter to populate the dataset
OracleDataAdapter oradap=new OracleDataAdapter ("select * from actor", Oracon);
Create a new dataset
DataSet ds=new DataSet ();
Fill DataSet
Oradap.fill (DS);
Create a new DataTable
DataTable _table=ds. Tables[0];
To view the number of columns of data in a table
int count=_table. Rows.Count;
datagrid1.datasource=_table;
Datagrid1.databind ();
To read data by DataReader:
To create a connection to a database
OracleConnection oracon=new oracleconnection ("User Id=112;data source=wmatech;password=112");
Create a new instance of the database operation
OracleCommand oracmd=new OracleCommand ("select * from actor", Oracon);
Open a database connection
Oracon.open ();
DataReader provides a way to read only incoming streams of rows from a database.
OracleDataReader orard= Oracmd.executereader ();
String Szhtml= "";
while (Orard.read ())
{
Szhtml+=orard[0]. ToString () + "" +orard[1]. ToString () + "" +orard[2]. ToString () + "
";
}
Orard.close ();
To close a database connection
Oracon.close ();
Response.Write (szhtml);
Manipulating the database by command
To create a connection to a database
OracleConnection oracon=new oracleconnection ("User Id=112;data source=wmatech;password=112");
Create a new instance of the database operation
OracleCommand oracmd=new OracleCommand ("update actor set name= ' 123453 ' where id= ' admin '", oracon);
Oracon.open ();
EXECUTENONQUERY executes Transact-SQL statements against the connection and returns the number of rows affected.
int Effnum=oracmd.executenonquery ();
Response.Write (Effnum. ToString ());
Oracon.close ();
About the use of transaction functions
To create a connection to a database
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/csharp/
OracleConnection oracon=new oracleconnection ("User Id=112;data source=wmdb;password=112");
OracleCommand oracmd=new OracleCommand ();
Open connection
Oracon.open ();
Create a new instance of a transaction object
OracleTransaction oratact=oracon.begintransaction ();
Oracmd.connection=oracon;
Bind transaction object to command
Oracmd.transaction=oratact;
Try
{
Inserts the specified column of a table's row that satisfies a condition into another table
oracmd.commandtext= INSERT INTO Yz_tranetp_probpow (Oid,parentid,shiptype,amount,ton,weight,custnum,cubmeter, Standbox,shipchara,busrange) Select Oid,parentid,shiptype,amount,ton,weight,custnum,cubmeter,standbox,shipchara, Busrange from Yz_tranetp_probpow_app where seqappid= ' "+appid+" ' and needupdated=1 ';
Oracmd.executenonquery ();
oracmd.commandtext= "Update Yz_tranetp_probpow_app set needupdated=0 where seqappid= '" +appid+ "";
Oracmd.executenonquery ();
No errors, execute Submit command
Oratact.commit ();
}
catch (Exception ex)
{
Error occurred, execute rollback command
Oratact.rollback ();
Pop-up window display error
Response.Write ("");
}
Finally
{
Close connection
Oracon.close ();
}