how to get all updated in database and display in label in C#

how to get all updated in database and display in label in C#

Page 1 of 1

1 Replies - 2063 Views - Last Post: 05 June 2009 - 06:25 PM Rate Topic: -----

#1 dnegrana  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-June 09

how to get all updated in database and display in label in C#

Post icon  Posted 05 June 2009 - 05:05 PM

I am running oracle update command. The update works fine but i need to display the rows affected in label.

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 => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: how to get all updated in database and display in label in C#

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: how to get all updated in database and display in label in C#

Posted 05 June 2009 - 06:25 PM

Then query the database with a SELECT statement to get those rows. Just updating the table will not return the resulting changes to you, you need to go get the data.

Issue the query with the same WHERE statement that you used in your UPDATE command. This will get you all the updated rows.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1