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>
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 ();
}
}
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.