Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how can keep a value which it was recorded in database in variable before i updated it? i want the old value for an operation with new value,
example:
NewValue - OldValue = VariableValue
230 - 200 = 30,
by the way the OldValue is NewValue before i updated it.
can u give me an idea about it, if it's possible.
private void ChargerKiloVoitures()
{
			
try {
	_bd.Command.CommandText = "SELECT Kilometrage FROM Voitures " +
	"WHERE NumeroMatricule = \"" + CBNumMatricule.Text + "\"";
	Debug.WriteLine( Environment.NewLine );
	Debug.WriteLine( _bd.Command.CommandText );
	_bd.Reader = _bd.Command.ExecuteReader();
if ( _bd.Reader.Read());
	this.analogCounter2.Number = int.Parse(_bd.Reader["Kilometrage"].ToString());
	this.analogCounter1.Number = this.analogCounter2.Number + VidangeConstant;
					
					
   //i have problem here exactly 
	int OldKilometrage = int.Parse(_bd.Reader["Kilometrage"].ToString());
	int NewKilometrage = int.Parse(_bd.Reader["Kilometrage"].ToString());
	KiloMetrag.Value = NewKilometrage-OldKilometrage;
					
}//if
	_bd.Reader.Close();

}//try
	catch (Exception ex) {
		Debug.WriteLine( Environment.NewLine );
		Debug.WriteLine( ex.Message );
	MessageBox.Show("Une erreur a été détectée : " + Environment.NewLine + ex.Message, "Erreur");
	}//catch

}
Posted
Updated 29-Aug-11 9:58am
v3

What do you want to "keep"? You are showing calculations as though you're trying to prove some math operation. Programming languages don't work like that.

You will have a function that accepts the changes, something with a signature like:

private void UpdateDatabase(int myItemID, int newValue)
{
   // this is where you should be updating things
}


At this point, you have the newValue, and before you update the database, you can just fetch a copy of the old value from the database. Use a query to get the value.

From there, you can do whatever math you want to, or log, or whatever turns your crank.

Cheers.
 
Share this answer
 
Save it as a separate variable.

BTW, why are you making your examples backwards from the way it's represented in the code? That does nothing more than confuse people.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900