I am developing a program that needs to compare a key from a database column with IsolatedStorageFile content. I'm able to get both the column value from the SQL database and also the file content from the IsolatedStorageFile. However, I am not able to compare both files to see if they match.
Here's my code that gets the value from database column:
using (SqlConnection sqlConn = new SqlConnection(ConnString))
{
int dbID = 1;
SqlCommand sqlCmd = new SqlCommand("SELECT serialKey FROM activationTable WHERE id = @id", sqlConn);
sqlCmd.Parameters.AddWithValue("@id", dbID);
sqlConn.Open();
string dBSerialKey = sqlCmd.ExecuteScalar().ToString();
Lbl_CheckDB.Text = dBSerialKey;
}
And here's my code that gets the content from the IsolatedStorageFile:
using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null))
{
if (isolatedStorageFile.FileExists("Settings.txt"))
{
using (IsolatedStorageFileStream isolatedStorageFileStream = new IsolatedStorageFileStream("Settings.txt", FileMode.Open, isolatedStorageFile))
{
using (StreamReader streamReader = new StreamReader(isolatedStorageFileStream))
{
string readLine = streamReader.ReadToEnd();
Lbl_CheckUserKey.Text = readLine;
}
}
}
}
And here's how I'm trying to compare both keys:
if (Lbl_CheckUserKey.Text == Lbl_CheckDB.Text)
{
Lbl_BothKeys.Text = "Valid Keys!";
}
else
{
Lbl_BothKeys.Text = "Invalid Keys!";
}
I want to be able to compare both keys, and if they are the same, it should update my Lbl_BothKeys.Text = "Valid Keys!";
But the result that I keep getting is: "Invalid Keys!", even when both keys are the same.