See my Code below.
public class OracleDataQuery
{
public delegate void QueryCompleted();
private static OracleConnection m_Conn;
private OracleCommand o_command = new OracleCommand();
private OracleDataAdapter o_DataAdapter;
private DataSet o_DataSet;
///<summary>
///Event raised at the end of a query, used to bind the datagridview async
///</summary>
///<remarks></remarks>
public event QueryCompleted queryCompleted;
public DataSet m_Dataset
{
get { return o_DataSet; }
}
public bool ConnectTo(string strConnectionString)
{
m_Conn = new OracleConnection(strConnectionString);
try
{
m_Conn.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
//throw;
}
//finally
//{
// m_Conn.Close();
//}
if (m_Conn.State == ConnectionState.Open)
{
return true;
}
else
return false;
}
// Public Function GetState() As ConnectionState
// GetState = mConn.State
//End Function
/// <summary>
/// Get the status of the Database
////// </summary>
/// <returns>Return a value from the Enum ConnectionState</returns>
public ConnectionState GetState()
{
return m_Conn.State;
}
/// <summary>
/// Abort query
/// </summary>
public void InterruptQuery()
{
o_command.Cancel();
}
public void ExecuteQuery(Object sqlQuery)
{
try
{
o_command.CommandType = CommandType.Text;
o_command.CommandText = sqlQuery.ToString();
o_command.Connection = m_Conn;
o_command.ExecuteReader();
//o_command.ExecuteNonQuery();
o_DataAdapter = new OracleDataAdapter(o_command);
o_DataSet = new DataSet();
o_DataAdapter.Fill(o_DataSet);
}
catch (ThreadAbortException e)
{
throw new Exception("Current operation was aborted", e.InnerException);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
// MessageBox.Show(ex.Message);
}
finally
{
queryCompleted();
}
}
public void UpdateQuery(Object sqlquery)
{
try
{
o_command.CommandType = CommandType.Text;
//sqlquery = m_Conn;
o_command.CommandText = sqlquery.ToString();
o_command.Connection = m_Conn;
o_command.ExecuteNonQuery();
o_DataAdapter = new OracleDataAdapter(o_command);
o_DataSet = new DataSet();
o_DataAdapter.Fill(o_DataSet);
}
catch (ThreadAbortException e)
{
throw new Exception("Current Operation was aborted", e.InnerException);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
queryCompleted();
}
}
/// <summary>
/// Clear the internal object after executed a query
/// </summary>
public void Clear()
{
if (o_DataAdapter != null) o_DataAdapter.Dispose();
if (o_DataSet != null) o_DataSet.Dispose();
}
/// <summary>
/// Close the connection to the Database
/// </summary>
public void Disconnect()
{
try
{
if (m_Conn != null)
{
if (m_Conn.State == ConnectionState.Open) m_Conn.Close();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex.InnerException);
}
}
~OracleDataQuery()
{
}
}
Mod Edit: Please use code tags when posting your code. Code tags are used like so =>
Thanks,
PsychoCoder

New Topic/Question
Reply




MultiQuote




|