Data #region Using
Using System;
Using System.Configuration;
Using System.Data;
Using Oracle.DataAccess.Client;
#endregion
Namespace WIS. Base.data
{
///<summary>
<table style= "font-size:12px" >
<tr><td><b> filename </b>:DbObject.cs</td></tr>
<tr><td><b> function Description </b>: Data-tier base class, providing basic operations on underlying data </td></tr>
<tr><td><b> founder </b>: Xiachuntaoxchuntao@163.comQq:23106676</td></tr>
<tr><td><b> creation Time </b>:2005-05-28 </td></tr>
</table>
</summary>
public class DBObject
{
#region member Variable
<summary>
<table style= "font-size:12px" >
<tr><td><b> function Description </b>:oracle data Connection object </td></tr>
<tr><td><b> founder </b>: Xiachuntao </td></tr>
<tr><td><b> creation Time </b>:2005-05-28 </td></tr>
</table>
</summary>
protected OracleConnection Connection;
<summary><table style= "font-size:12px" >
<tr><td><b> function Description </b>: Data connection string </td></tr>
<tr><td><b> founder </b>: Xiachuntao </td></tr>
<tr><td><b> creation Time </b>:2005-05-28 </td></tr>
</table></summary>
private string connectionString;
#endregion
#region Constructors
<summary><table style= "font-size:12px" >
<tr><td><b> function Description </b>: constructors, initializing data connection objects using the default data connection string connectionstring in the configuration file </td>< /tr>
<tr><td><b> founder </b>: Xiachuntao </td></tr>
<tr><td><b> creation Time </b>:2005-05-28 </td></tr>
</table></summary>
Public DBObject ()
{
connectionString = ConfigurationSettings.AppSettings.Get ("connectionString");//connection string obtained from web.config
Connection = new OracleConnection (connectionString);
}
<summary><table style= "font-size:12px" >
<tr><td><b> function Description </b>: constructors, initializing data connection objects based on the specified data connection string </td></tr>
<tr><td><b> founder </b>: Xiachuntao </td></tr>
<tr><td><b> creation Time </b>:2005-05-28 </td></tr>
</table></summary>
<param name= "newconnectionstring" > Data connection string </param>
Public DBObject (String newconnectionstring)
{
connectionString = newconnectionstring;
Connection = new OracleConnection (connectionString);
}
#endregion
#region Private Method
///<summary><table style= "font-size:12px"
///<tr><td> <b> function Description </b>: Creates a OracleCommand object for generating OracleDataReader </td></tr>
///< Tr><td><b> founder </b>: Xiachuntao </td></tr>
///<tr><td><b > Creation time </b>:2005-05-28 </td></tr>
///</table></summary>
///<param name= "storedprocname" > Stored procedure name </param>
///<param name= "Parameters" > Parameter Object List (array) of stored procedures </param>
///<returns>oraclecommand object </returns>
private OracleCommand Buildcommand (String storedprocname, idataparameter[] parameters)
{
oraclecommand command = new OracleCommand (Storedprocname, Connection);
command.commandtype = CommandType.StoredProcedure;
foreach (oracleparameter parameter in parameters)
{
Command. Parameters.Add (parameter);
}
return command;
}
#endregion
#region Run stored procedures
///<summary>
///<table style= font-size : 12px "
///<tr><td><b> function Description </b>: Run stored procedures, get the number of affected rows, return the results of the stored procedure run </td> </tr>
///<tr><td><b> creator </b>: Xiachuntao </td></tr>
///<tr><td><b> creation time </b>:2005-05-28 </td></tr>
///</ Table>
///</summary>
///<param name= "storedprocname" > Stored procedure name </ Param>
///<param name= "parameters" > stored procedure Parameter Objects list (array) </param>
///< param name= "rowsaffected" > Outbound Parameters: The number of record rows affected by the execution of the stored procedure </param>
///<returns> Run results of stored procedures </ Returns>
public Object Runprocedure (String storedprocname, idataparameter[] parameters, out int rowsaffected)
{
object result;
//if (Connection.State.ToString () = = "Closed") Connection.Open ();
connection.open ();
oraclecommand command = Buildcommand (storedprocname, parameters);
rowsaffected = command. ExecuteNonQuery ();
//Returns a value if there is a "returnvalue" parameter, otherwise null
bool Blnhasreturn = false;
for (int i=0;i<parameters. length;i++)
{
if (parameters[i). Direction = = ParameterDirection.ReturnValue)
{
Blnhasreturn = true;
break;
}
}
if (blnhasreturn)
result = command. parameters["ReturnValue"]. Value;
else
result = null;
Connection.close ();
return result;
}
<summary><table style= "font-size:12px" >
<tr><td><b> function Description </b>: Run the stored procedure, return the resulting OracleDataReader object </td></tr>
<tr><td><b> founder </b>: Xiachuntao </td></tr>
<tr><td><b> creation Time </b>:2005-05-28 </td></tr>
</table></summary>
<param name= "storedprocname" > Stored procedure name </param>
<param name= "Parameters" > stored procedure Parameter object list (array) </param>
<returns>oracledatareader Objects </returns>
Public OracleDataReader runprocedure (string storedprocname, idataparameter[] parameters)
{
OracleDataReader Returnreader;
Connection.Open ();
OracleCommand command = Buildcommand (storedprocname, parameters);
Command.commandtype = CommandType.StoredProcedure;
Returnreader = command. ExecuteReader ();
Connection. Close ();
return returnreader;
}
<summary><table style= "font-size:12px" >
<tr><td><b> function Description </b>: Run a stored procedure, create a DataSet object,
Stores the results of the run in the specified DataTable, returning the DataSet object </td></tr>
<tr><td><b> founder </b>: Xiachuntao </td></tr>
<tr><td><b> creation Time </b>:2005-05-28 </td></tr>
</table></summary>
<param name= "storedprocname" > Stored procedure name </param>
<param name= "Parameters" > stored procedure Parameter object list (array) </param>
<param name= "tablename" > Datasheet name </param>
<returns>dataset Objects </returns>
Public DataSet runprocedure (string storedprocname, idataparameter[] parameters, string tablename)
{
DataSet DataSet = new DataSet ();
Connection.Open ();
OracleDataAdapter SqlDA = new OracleDataAdapter ();
Sqlda.selectcommand = Buildcommand (storedprocname, parameters);
Sqlda.fill (DataSet, TableName);
Connection.close ();
return dataSet;
}
<summary><table style= "font-size:12px" >
<tr><td><b> function Description </b>: Runs the stored procedure, stores the results in the specified table of the existing DataSet object, no return value </td></tr>
<tr><td><b> founder </b>: Xiachuntao </td></tr>
<tr><td><b> creation Time </b>:2005-05-28 </td></tr>
</table></summary>
<param name= "storedprocname" > Stored procedure name </param>
<param name= "Parameters" > stored procedure Parameter object list (array) </param>
<param name= "DataSet" >dataset object </param>
<param name= "tablename" > Datasheet name </param>
public void Runprocedure (String storedprocname, idataparameter[] Parameters, DataSet DataSet, string tablename)
{
Connection.Open ();
OracleDataAdapter SqlDA = new OracleDataAdapter ();
Sqlda.selectcommand = Buildcommand (storedprocname, parameters);
Sqlda.fill (DataSet, TableName);
Connection.close ();
}
#endregion
#region Run SQL statements
<summary><table style= "font-size:12px" >
<tr><td><b> function Description </B>: Run the SQL statement associated with the write database, and return the number of affected rows </td></tr>
<tr><td><b> founder </b>: Xiachuntao </td></tr>
<tr><td><b> creation Time </b>:2005-05-28 </td></tr>
</table></summary>
<param name= "SqlString" >sql statement </param>
<returns> affect rows </returns>
public int Execnonquery (string sqlstring)
{
int rowaffected;
if (Connection.State.ToString () = = "Closed") Connection.Open ();
Connection.Open ();
OracleCommand command = new OracleCommand (SqlString, Connection);
rowaffected = command. ExecuteNonQuery ();
Connection.close ();
return rowaffected;
}
///<summary><table style= "font-size:12px"
///<tr><td> <b> function Description </B>: Run SQL statement, return OracleDataReader object </td></tr>
///<TR><TD ><b> founder </b>: Xiachuntao </td></tr>
///<tr><td><b> creation Time </b >:2005-05-28 </td></tr>
///</table></summary>
///< param name= "SqlString" >sql statement </param>
///<returns>sqldatareader Object </returns>
public oracledatareader execsqlstring (string sqlstring)
{
OracleDataReader Returnreader;
if (Connection.State.ToString () = = "Closed") Connection.Open ();
Connection.Open ();
OracleCommand command = new OracleCommand (SqlString, Connection);
Returnreader = command. ExecuteReader ();
Connection. Close ();
return returnreader;
}
<summary><table style= "font-size:12px" >
<tr><td><b> function Description </b>: Run SQL statement, return DataSet object </td></tr>
<tr><td><b> founder </b>: Xiachuntao </td></tr>
<tr><td><b> creation Time </b>:2005-05-28 </td></tr>
</table></summary>
<param name= "string" >sql statement </param>
<param name= "tablename" > Datasheet name </param>
<returns>dataset Objects </returns>
Public DataSet execsqlstring (string sqlstring, String tablename)
{
DataSet DataSet = new DataSet ();
if (Connection.State.ToString () = = "Closed") Connection.Open ();
Connection.Open ();
OracleDataAdapter SqlDA = new OracleDataAdapter ();
Sqlda.selectcommand = new OracleCommand (SqlString, Connection);
Sqlda.fill (DataSet, TableName);
Connection.close ();
return dataSet;
}
<summary><table style= "font-size:12px" >
<tr><td><b> function Description </b>: Runs the SQL statement, stores the results in the specified table of the existing DataSet object, no return value </td></tr>
<tr><td><b> founder </b>: Xiachuntao </td></tr>
<tr><td><b> creation Time </b>:2005-05-28 </td></tr>
</table></summary>
<param name= "SqlString" >sql statement </param>
<param name= "DataSet" >dataset object </param>
<param name= "tablename" > Datasheet name </param>
public void execsqlstring (string sqlstring, DataSet DataSet, string tablename)
{
if (Connection.State.ToString () = = "Closed") Connection.Open ();
Connection.Open ();
OracleDataAdapter SqlDA = new OracleDataAdapter ();
Sqlda.selectcommand = new OracleCommand (SqlString, Connection);
Sqlda.fill (DataSet, TableName);
Connection.close ();
}
<summary><table style= "font-size:12px" >
<tr><td><b> function Description </b>: Runs the SQL statement, returns the first column of the first row of the query result, ignoring other rows or columns </td></tr>
<tr><td><b> founder </b>: Xiachuntao </td></tr>
<tr><td><b> creation Time </b>:2005-05-28 </td></tr>
</table></summary>
<param name= "SqlString" >sql statement </param>
<returns> affect rows </returns>
public Object Execscalar (string sqlstring)
{
Object Returnscalar;
if (Connection.State.ToString () = = "Closed") Connection.Open ();
Connection.Open ();
OracleCommand command = new OracleCommand (SqlString, Connection);
returnscalar = command. ExecuteScalar ();
Connection.close ();
return returnscalar;
}
#endregion
#region Close data connection
///<summary><table style= "font-size:12px"
///<tr><td><b> Function Description </b>: Close data connection </td></tr>
///<tr> <td><b> founder </b>: Xiachuntao </td></tr>
///<tr><td><b> creation time </b>:2005-05-28 </td></tr>
///</table></summary>
public void Close ()
{
if (Connection.State.ToString () = = "Open"
connection.close ();
}
#endregion
#region destructor
<summary><table style= "font-size:12px" >
<tr><td><b> function Description </b>: destructor, aftercare, release data connection </td></tr>
<tr><td><b> founder </b>: Xiachuntao </td></tr>
<tr><td><b> creation Time </b>:2005-05-28 </td></tr>
</table></summary>
~dbobject ()
{
if (Connection.State.ToString () = = "Open")
Connection.close ();
Connection.dispose ();
}
#endregion
}
}