NewHelpNeeder
NewHelpNeeder

Reputation: 693

Cannot convert object to a string

I have encrypted every item in MS Access file using AES. Encryption works great. The problem is that I am getting an error: Argument 1: cannot convert from 'object' to 'string' On lines like these: security.Decrypt(readPersonalData.GetValue(1), storedAuth.Password, storedAuth.UserName)

How can I avoid this?

        if (readPersonalData.HasRows)
        {
            while (readPersonalData.Read())
            {
                // Count all entries read from the reader.
                countEntries++;


                txtDisplay.Text += "=== Entry ID: " + readPersonalData.GetValue(0) + " ===" + Environment.NewLine;
                txtDisplay.Text += "Type: " + security.Decrypt(readPersonalData.GetValue(1), storedAuth.Password, storedAuth.UserName) + Environment.NewLine;
                if (!readPersonalData.IsDBNull(2)) txtDisplay.Text += "URL: " + security.Decrypt(readPersonalData.GetValue(2), storedAuth.Password, storedAuth.UserName) + Environment.NewLine;
                if (!readPersonalData.IsDBNull(3)) txtDisplay.Text += "Software Name: " + security.Decrypt(readPersonalData.GetValue(3), storedAuth.Password, storedAuth.UserName) + Environment.NewLine;
                if (!readPersonalData.IsDBNull(4)) txtDisplay.Text += "Serial Code: " + security.Decrypt(readPersonalData.GetValue(4), storedAuth.Password, storedAuth.UserName) + Environment.NewLine;
                if (!readPersonalData.IsDBNull(5)) txtDisplay.Text += "User Name: " + security.Decrypt(readPersonalData.GetValue(5), storedAuth.Password, storedAuth.UserName) + Environment.NewLine;
                if (!readPersonalData.IsDBNull(6)) txtDisplay.Text += "Password: " + security.Decrypt(readPersonalData.GetValue(6), storedAuth.Password, storedAuth.UserName) + Environment.NewLine;
                txtDisplay.Text += Environment.NewLine;
            }
        }

Upvotes: 1

Views: 805

Answers (1)

ipr101
ipr101

Reputation: 24236

You could try -

txtDisplay.Text += "Type: " + security.Decrypt(readPersonalData.GetString(1), storedAuth.Password, storedAuth.UserName) + Environment.NewLine;

Which should return a string that can be passed to the security.Decrypt function.

Upvotes: 2

Related Questions