简体   繁体   中英

C# Replacing value in datatable

Scenario: App contains DataGridViews, I am populating the DataGridViews from a Database. All the data in the Database is encrypted so after I fill my DataTable I need to cycle through every entry in the DataTable through the decryption methods and place back in the same spot in the DataTable. How would I do such a task? Or is there a way I can decrypt the data as it is entering the dataTable?

SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(query, conn);
SQLiteCommandBuilder commandBuilder = new SQLiteCommandBuilder(dataAdapter);
DataTable dataTable = new DataTable();
dataTable.Locale = System.Globalization.CultureInfo.Invaria…
dataAdapter.Fill(dataTable);
//Decrypt cells
int i;
foreach (DataRow row in dataTable.Rows)
{
i = 0;
    foreach (var item in row.ItemArray)
    {
        //This doesn't work
        row.ItemArray[i] = Crypto.Decrypt(item.ToString());
        i++;
    }
}
return dataTable;
for (int i = 0; i < dataTable.Rows.Count; i++)
{
    for (int j = 0; j < dataTable.Columns.Count; j++)
    {
        dataTable.Rows[i][j] = Crypto.Decrypt(dataTable.Rows[i][j].ToString());
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM