472,785 Members | 1,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,785 software developers and data experts.

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
14 6698
Plater
7,872 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
7,872 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
7,872 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
7,872 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
7,872 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
7,872 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
7,872 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

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

Similar topics

10
by: sffan | last post by:
I am new to database programming and was curious how others solve the problem of storing encrypted in data in db table columns and then subsequently searching for these records. The particular...
5
by: Nico | last post by:
My database have 20 tables and many users. I wish to store encrypted data in 3 tables and have only 3 users have access to them, walking into tables or using forms. Can someone point me a direct...
4
by: Burke Atilla | last post by:
While encrypting data with DES through CryptoStream makes encrypted data bigger than original string. if we have 8 byte key and 8 byte of data then the mode is ECB. output encrypted data is 16 bytes...
2
by: Leonardo D'Ippolito | last post by:
Hi! I have two .NET win apps that need to communicate on a TCP/IP network. 'App A' must ask 'app B' if it's allowed to do some task, and 'app B' must authorize or prohibit it. How can I do...
8
by: robert | last post by:
Hello, I want to put (incrementally) changed/new files from a big file tree "directly,compressed and password-only-encrypted" to a remote backup server incrementally via FTP,SFTP or DAV.... At...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
2
by: Ivan | last post by:
I have a class Foo which have two property. I have a thread that do some process and update class Foo int B. I have a datagridview on main form. this datagridview data source to this class Foo and...
2
by: Rick Shaw | last post by:
Hi, I have a problem with the datagridview not refreshed when the application first appear on the screen. The datagridview display data from a table in the dataset. At the same time, I've added...
2
by: Bernard Dhooghe | last post by:
The information center writes: "Encryption Algorithm: The internal encryption algorithm used is RC2 block cipher with padding, the 128-bit secret key is derived from the password using a MD2...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.