using System;
using ;
using ;
using ;
using ;
namespace
{
//Base class for data access (based on OleDb)
public partial class DbHelperOleDb
{
//The database connection string is configured in
public static string ConnectionString = ;
public DbHelperOleDb()
{
}
/// <summary>
/// Execute SQL statement to return the number of records affected
/// </summary>
/// <param name="strSql">SQL statement</param>
/// <returns>Number of records affected</returns>
public static int ExecuteSql(string strSql)
{
using (OleDbConnection conn = new OleDbConnection(ConnectionString))
{
using (OleDbCommand cmd = new OleDbCommand(strSql, conn))
{
try
{
();
return ();
}
catch(OleDbException E)
{
();
throw new Exception();
}
}
}
}
/// <summary>
/// Execute multiple SQL statements to implement database transactions
/// </summary>
/// <param name="SqlStrList">Multiple SQL statements</param>
public static void ExecuteSqlTran(ArrayList SqlStrList)
{
using (OleDbConnection conn = new OleDbConnection(ConnectionString))
{
();
OleDbCommand cmd = new OleDbCommand();
= conn;
OleDbTransaction tx = ();
= tx;
try
{
for (int n = 0; n < ; n++)
{
string strSql = SqlStrList[n].ToString();
if (().Length > 1)
{
= strSql;
();
}
}
();
}
catch ( E)
{
();
throw new Exception();
}
}
}
/// <summary>
/// Execute SQL statement with a stored procedure parameter
/// </summary>
/// <param name="strSql">SQL statement</param>
/// <param name="content">parameter content, such as an article with a complex format</param>
/// <returns>Number of records affected</returns>
public static int ExecuteSinglePro(string strSql, string content)
{
using (OleDbConnection conn = new OleDbConnection(ConnectionString))
{
OleDbCommand cmd = new OleDbCommand(strSql, conn);
OleDbParameter myParameter = new OleDbParameter("@content",);
= content;
(myParameter);
try
{
();
return ();
}
catch (OleDbException E)
{
throw new Exception();
}
finally
{
();
();
}
}
}
/// <summary>
/// Execute a statement to calculate the query result and return the query result
/// </summary>
/// <param name="strSql">SQL statement</param>
/// <returns>Query results</returns>
public static object GetSingle(string strSql)
{
using (OleDbConnection conn = new OleDbConnection(ConnectionString))
{
using (OleDbCommand cmd = new OleDbCommand(strSql, conn))
{
try
{
();
object obj = ();
if ((Equals(obj, null)) || Equals(obj, ))
{
return null;
}
else
{
return obj;
}
}
catch (OleDbException E)
{
();
throw new Exception();
}
}
}
}
/// <summary>
/// Return to OleDbDataReader
/// </summary>
/// <param name="strSql">Query statement</param>
/// <returns>OleDbDataReader</returns>
public static OleDbDataReader ExecuteReader(string strSql)
{
OleDbDataReader dr = null;
using (OleDbConnection conn = new OleDbConnection(ConnectionString))
{
using(OleDbCommand cmd = new OleDbCommand(strSql,conn))
{
try
{
();
= strSql;
= ;
dr = ();
}
catch
{
();
();
();
}
}
}
return dr;
}
/// <summary>
/// Execute the query statement and return the DataSet
/// </summary>
/// <param name="strSql">Query statement</param>
/// <returns>DataSet</returns>
public static DataSet Query(string strSql)
{
using (OleDbConnection conn = new OleDbConnection(ConnectionString))
{
DataSet ds = new DataSet();
try
{
();
OleDbDataAdapter da = new OleDbDataAdapter(strSql, conn);
(ds, "ds");
}
catch (OleDbException E)
{
throw new Exception();
}
return ds;
}
}
}
}