Samia Souror

Samia Souror

  • NA
  • 33
  • 5.2k

How to get value from sting array and use it ?

Nov 26 2018 4:15 PM
Welcome,
 
I have string array hold some keys used to decrypt column data in the database. but only the first value in the column is decrypted correctly.
 
private void button8_Click(object sender, EventArgs e)
{
this.txtKey.Hide();
this.lblkey.Hide();
OracleConnection conn;
using (conn = new OracleConnection(oradb))
{
OracleCommand select = new OracleCommand("select EMPNO, ENAME,JOB from EMP", conn);
conn.Open();
OracleDataReader reader = select.ExecuteReader();
Int64 v_empno = 0;
String v_JOBvalue = "";
String Decryptjob = "";
Enigma enigma = new Enigma();
if (reader.HasRows)
{
foreach (var item in KeyList)
{
int i = 0;
string[] the_array = new string[KeyList.Count];
while (reader.Read())
{
v_empno = reader.GetInt32(0);
v_JOBvalue = reader.GetString(2);
the_array[i] = item.ToString();
Decryptjob = enigma.Decrypt(v_JOBvalue, the_array[i]);
// MessageBox.Show(" : value of job :" + v_JOBvalue + "decrypted using the key " + decryptedListKey);
/////////////////////////////////////////////////////////////////////////////////
OracleCommand update = new OracleCommand("update EMP set JOB =:JOB where EMPNO =:EMPNO", conn);
OracleParameter JOB = new OracleParameter("JOB", Decryptjob);
OracleParameter EMPNO = new OracleParameter("EMPNO", v_empno);
update.Parameters.Add(JOB);
update.Parameters.Add(EMPNO);
update.ExecuteNonQuery();
i++;
}}
MessageBox.Show("User updated!");
OracleDataAdapter a = new OracleDataAdapter("select * from EMP", conn);
DataTable t = new DataTable();
a.Fill(t);
dataGridView1.DataSource = t;
reader.Close();
} } }

Answers (5)