public class DataAgent
{
#region Variables
private string m_strConnectionString;
private OleDbConnection m_objConnection;
#endregion Variables
#region Functions
#region DataAgend
///
/// Initial Function
///
///
public DataAgent(string strConnection)
{
this.m_strConnectionString = strConnection;
}
#endregion DataAgend
#region OpenDataBase
///
/// function to open data base
///
private void OpenDataBase()
{
try
{
this.m_objConnection = new OleDbConnection();
this.m_objConnection.ConnectionString = this.m_strConnectionString;
if(this.m_objConnection.State != ConnectionState.Open)
{
this.m_objConnection.Open();
}
}
catch(Exception e)
{
throw e;
}
}
#endregion OpenDataBase
#region CloseDataBase
///
/// the function to cloase data base
///
private void CloseDataBase()
{
if(this.m_objConnection != null)
{
if(this.m_objConnection.State == ConnectionState.Open)
{
this.m_objConnection.Close();
}
}
}
#endregion
#region GetDataView
///
/// Execute the sql and return the default table view
///
/// Select String
/// DataView of the DataTable
public DataView GetDataView(string strSqlStat)
{
try
{
this.OpenDataBase();
OleDbDataAdapter objDataAdapter =
new OleDbDataAdapter(strSqlStat.Trim(),this.m_objConnection);
DataSet objDataSet = new DataSet();
objDataAdapter.Fill(objDataSet);
return objDataSet.Tables[0].DefaultView;
}
catch(Exception e)
{
throw e;
}
finally
{
this.CloseDataBase();
}
}
#endregion GetDataTable
#endregion Functions
}