467,188 Members | 1,416 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,188 developers. It's quick & easy.

Encrypted data in datagridview

hi guys..im new to datagridview and im wondering is there a way to convert an encrypted data in access and show it in a datagridview? im using C# and microsoft access

normally this is how to show data in datagridview:

OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="");
OleDbCommand command = conn.CreateCommand();
string strSQL = "SELECT * FROM Employee";
ds = new DataSet();
conn.Open();

command.CommandText = strSQL;
OleDbDataAdapter adapter = new OleDbDataAdapter(command);
adapter.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.ReadOnly = true;
conn.Close();
where should i change to decrypt those data before showing it in the datagrid?
Oct 8 '07 #1
  • viewed: 6025
Share:
14 Replies
Plater
Expert 4TB
Do you know how to un-encrypt it? If so, just run the decrypting on the data kep in the dataset?
Oct 8 '07 #2
Do you know how to un-encrypt it? If so, just run the decrypting on the data kep in the dataset?
yes..i know how to decrypt it. but what im doing is to decrypt it 1 at a time
eg. temp=(string)read["Username"];
encryption.decrypt(temp, true);
this decrypts the username only..the problem is i dont know how to show this in the datagrid. all this while i used this method only in a while loop.
eg.
while(read.read())
{
//decrypt
}
Oct 8 '07 #3
Plater
Expert 4TB
Well, populate your DataSet, then loop through the dataset.
Oct 8 '07 #4
Well, populate your DataSet, then loop through the dataset.
can you example please..:)
Oct 8 '07 #5
Plater
Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. //myq is a string with my SELECT sql statement
  2. //dbcon is my database connection
  3. //you will probably not use the Sql namespace but like odb namespace
  4. DataSet retval= new DataSet();
  5. SqlDataAdapter dba = new SqlDataAdapter(myq, dbcon);
  6. dba.Fill(retval);
  7. //now your dataset is populated with values
  8. //retval.Tables[0] will give you your DataTable
  9.  
  10. //then you can loop through
  11. foreach(DataRow r in retval.Tables[0].Rows)
  12. {
  13.    //decrypt the data in each column of the row and save it back to the row
  14. }
  15.  

Maybe someone knows a better way, but this is what came to my mind.
Oct 8 '07 #6
Expand|Select|Wrap|Line Numbers
  1. //myq is a string with my SELECT sql statement
  2. //dbcon is my database connection
  3. //you will probably not use the Sql namespace but like odb namespace
  4. DataSet retval= new DataSet();
  5. SqlDataAdapter dba = new SqlDataAdapter(myq, dbcon);
  6. dba.Fill(retval);
  7. //now your dataset is populated with values
  8. //retval.Tables[0] will give you your DataTable
  9.  
  10. //then you can loop through
  11. foreach(DataRow r in retval.Tables[0])
  12. {
  13.    //decrypt the data in each column of the row and save it back to the row
  14. }
  15.  

Maybe someone knows a better way, but this is what came to my mind.
it says that foreach statement cannot operate on variables of type system.data.datatable because it does not contain public definition for getenumerator...
Oct 8 '07 #7
Plater
Expert 4TB
it says that foreach statement cannot operate on variables of type system.data.datatable because it does not contain public definition for getenumerator...
Oops!
(I fixed it in the above code as well)
Use:
Expand|Select|Wrap|Line Numbers
  1. foreach(DataRow r in retval.Tables[0].Rows)
  2.  
Oct 8 '07 #8
Expand|Select|Wrap|Line Numbers
  1. foreach(DataRow r in retval.Tables[0].Rows)
  2.  
this works fine:) but i cant seem to get values out of the datagrid
is this even correct?
object value=datagridview1.columns["EmployeeUsername"];
then how do i change objects to strings and putting it back to the grid?
Oct 8 '07 #9
Plater
Expert 4TB
Try this:
Expand|Select|Wrap|Line Numbers
  1. //then you can loop through
  2. foreach(DataRow r in retval.Tables[0])
  3. {
  4.    //decrypt the data in each column of the row and save it back to the row
  5.    object o = r["mycolumnname"].Value;
  6.    //r["mycolumnname"] should also have a like .ColumnType property or something to tell you what the object really is
  7.    //If need be you can use o.GetType() to determine the valuetype too
  8. }
  9.  
Oct 8 '07 #10
Expand|Select|Wrap|Line Numbers
  1. foreach(DataRow r in retval.Tables[0])
  2. {
  3.    //decrypt the data in each column of the row and save it back to the row
  4.    object o = r["mycolumnname"].Value;
  5.    //r["mycolumnname"] should also have a like .ColumnType property or something to tell you what the object really is
  6.    //If need be you can use o.GetType() to determine the valuetype too
  7. }
  8.  
foreach(datarow r in retval.tables[0]) cannot be executed
i've head of cell formatting but how does it applies..
Oct 9 '07 #11
Plater
Expert 4TB
foreach(datarow r in retval.tables[0]) cannot be executed
i've head of cell formatting but how does it applies..
Did you switch it to:
foreach(datarow r in retval.tables[0].Rows)

???
Oct 9 '07 #12
Did you switch it to:
foreach(datarow r in retval.tables[0].Rows)
???
yes i did....
foreach(datarow r in retval.tables[0].Rows)
{
object o = r["EmployeeUserName"];
string a = (string) o;
string b = Encryption.Decrypt(a, true);
}
i used a messageBox.show(); to see the result it did change the values
next is to put the decrypted values inside the datagridview..any ideal how?
Oct 9 '07 #13
Plater
Expert 4TB
next is to put the decrypted values inside the datagridview..any ideal how?
Just assign them back again?

Expand|Select|Wrap|Line Numbers
  1. foreach(datarow r in retval.tables[0].Rows)
  2. {
  3.   object o = r["EmployeeUserName"];
  4.   string a = (string) o;
  5.   string b = Encryption.Decrypt(a, true);
  6.   //like this maybe?
  7.   r["EmployeeUserName"].value=b;
  8. }
  9.  
Oct 9 '07 #14
foreach(datarow r in retval.tables[0].Rows)
{
object o = r["EmployeeUserName"];
string a = (string) o;
string b = Encryption.Decrypt(a, true);
}
i got it!!!!
just add the r["employeename"] = 'decrypted value'; inside the foreeach loop

thanks man!!!!!!!!!
thank you for ur precious time!!!!!!!!!
thank you so much Plater!!!! really appriciate your help!!!!!!!
Oct 9 '07 #15

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by sffan@hotmail.com | last post: by
2 posts views Thread by Leonardo D'Ippolito | last post: by
5 posts views Thread by Michael Sperlle | last post: by
2 posts views Thread by Rick Shaw | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.