It sounds by your comments like you are a novice - so please fogive me if this isn't the case:
In your C# code you probably have some code that does the following
Get X From COM port
Write X to database table
So, you need a field in your class to store the 'old' value of X.
private int oldX = -1;
I initialise it with -1 on teh assumption that it is not possible to receive -1 from the COM port...
Now your code can change to...
Get X from COM PORT
if (X != oldX)
{
oldX = X;
write X to database table
}