Oracle database Operations Class (C #)

Source: Internet
Author: User
Tags oracleconnection table name oracle database
oracle| Data | Database connects Oracle with OracleConnection
Configure <add key= "Oracle" value= Data source=xxx in web.config; User id=xxx; Password=xxx "/>

public System.Data.OracleClient.OracleConnection CNN;

<summary>
Open a database connection
</summary>
public void Open ()
{
Cnn=new OracleConnection (system.configuration.configurationsettings.appsettings["Oracle");
Cnn. Open ();
}

<summary>
Open the database connection and return to CNN
</summary>
Public OracleConnection opencnn ()
{
Cnn=new OracleConnection (system.configuration.configurationsettings.appsettings["Oracle");
Cnn. Open ();
return (CNN);
}

<summary>
To close a database connection
</summary>
public void Close ()
{
Cnn. Close ();
}

<summary>
return dataset
</summary>
<param name= "Cmdstring" ></param>
<param name= "tablename" ></param>
<returns></returns>
Public DataSet GetDataSet (string cmdstring,string tablename)
{
Open ();
OracleDataAdapter Myda =new oracledataadapter ();
Myda.selectcommand = new OracleCommand (CMDSTRING,CNN);
DataSet myDS =new DataSet ();
Myda.fill (Myds,tablename);
Close ();
return myds;
}

<summary>
Back to OleDbDataReader
</summary>
<param name= "Cmdstring" ></param>
<returns></returns>
Public OracleDataReader Getdatareader (string cmdstring)
{
Open ();
OracleCommand mycmd =new OracleCommand (CMDSTRING,CNN);
OracleDataReader mydr =mycmd.executereader ();
return mydr;
}

<summary>
Returns the number of rows that affect the database
</summary>
<param name= "Cmdstring" ></param>
<returns></returns>
public int ExecuteSQL (string cmdstring)
{
Open ();
OracleCommand mycmd =new OracleCommand (CMDSTRING,CNN);
int CMD =mycmd.executenonquery ();
Close ();
return CMD;
}

<summary>
Bang Ding Drodownlist
</summary>
<param name= "drodlist" ></param> control name
<param name= "SQL" ></param> Connection strings
<param name= "tablename" ></param> table name
<param name= "DATATEXTFD" ></param> data source fields that provide text content
<param name= "DATAVALUEFD" ></param> data source fields that provide values for list items
public void Drolist (DropDownList drodlist,string sql,string tablename,string datatextfd,string)
{
Open ();
OracleDataAdapter Myda =new OracleDataAdapter (SQL,CNN);
MyDa.SelectCommand.CommandType = CommandType.Text;
DataSet myDS =new DataSet ();
Try
{
Myda.fill (Myds,tablename);
Drodlist.datasource = Myds.tables[tablename];
Drodlist.datatextfield = DATATEXTFD;
Drodlist.datavaluefield = DATAVALUEFD;
Drodlist.databind ();
}
catch (Exception e)
{
Response.Write (E.message);
}
Finally
{
Close ();
}
}





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.