473,385 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 6770
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.