Programming, database, security, Oracle, .NET, C#, PHP, Travel

Archive for the “.NET” Category

If you install VS2005 and then ODP.Net you will probably get a strange error when you will try to use Oracle Explorer for the first time:

Package ‘Oracle Developer Tools for Visual Studio .NET’ has failed
to load properly ( GUID = {D601BB95-E404-4A8E-9F24-5C1A462426CE}).
Please contact package vendor for assistance. Application restart is
recommended, due to possible environment corruption. Would you like to
disable loading this package in the future? You may use ‘devenv /resetskippkgs’ to re-enable package loading.

The problem is an assembly mismatch. As Christian Shay (principal product manager for ODP.net at Oracle) said in an announcement, there are 2 options to solve this issue:
1. My recommended solution:

Execute the following command from a command prompt:

gacutil /i <Oracle Home>\odp.net\bin\2.x\Oracle.DataAccess.dll

where is the Oracle Home directory where you installed ODT 2005. For example, on my machine is c:\oracle\product\10.2.0\client_1.

2. Reinstall:

Deinstall ODP.NET 1.x from your machine (if you’re not using it) and install ODP.NET 2.0 in the same Oracle Home.
Andreihttp://www.webxpert.ro

This is intended to be a tutorial of how to use ASP.Net DataGrid for view, edit, insert and delete items from an XML file.
Many people probably would need to keep some small amount of data in XML files rather than in the database. Manipulating this data is very simple and it can be made with a DataGrid, and this is the scope of this article, to show you how.

Then we will create a new webform page named xmlDataGrid.aspx, and add a DataGrid control, a Button and set tht title, exactly like in the above screenshot.
AutoGenerateColumns must set to false and must add the following columns in the DataGrid:
– Title binded to TITLE DataField
– Artist binded to ARTIST DataField
– Country binded to COUNTRY DataField
– Price binded to PRICE DataField
– Year binded to YEAR DataField
– Style binded to STYLE DataField
– Button column for “Edit, Update, Cancel”
– Button column for “Delete”

In order to add some functionality to the DataGrid, first of all we need to load the data to the grid.
In the Page_Load event, we wil fill the dataset with XML data and then bind the DataGrid to this dataset:

//the dataset that will keep the dataSystem.Data.DataSet myDataSet = newSystem.Data.DataSet();

//populate the dataset from XMLvoid FillData(){//read the XML into the DataSet
myDataSet.ReadXml(Server.MapPath("source.xml"));//set the grid’s DataSource to DataSet
dgCatalog.DataSource = myDataSet;}

Now the DataGrid will display the data like in the above screenshot. We need to add functionalities for Edit, Delete and Update events.
Before writing these events, we must write the function that will save the dataset back to disk as XML file.

A little complicated is Cancel event. Because we have a button that adds a new row to the dataset and change the text for Update link to “Insert”, we must assure that on Cancel event the text for the link is set back to “Update”.

The “Add new row” button adds non-default functionality to the DataGrid control. A simple DataGrid does not have an event for Add or Insert. We used a trick to do this by adding a blank row to the dataset and then turn that row into edit mode and change the text for Update link to “Insert”.

//event occurs when "Add new row" button is pressedvoid btnAdd_Click(object sender, EventArgs e){//add an extra row to the dataSet
InsertEmpty();//the new row is the last one in the dataset
dgCatalog.EditItemIndex = myDataSet.Tables[0].Rows.Count-1;

//procedure that add an empty row to the DataSetprivatevoid InsertEmpty(){//insert a new row at the end of the dataSet
myDataSet.Tables[0].Rows.InsertAt(myDataSet.Tables[0].NewRow(), myDataSet.Tables[0].Rows.Count);}

We missed one single event: Update. Here’s the code (it’s a little complicated due to the duble functionality: Update and Insert:

//event occurs when Update or Insert link is clickedvoid dgCatalog_UpdateCommand(object sender, DataGridCommandEventArgs e){System.Data.DataRow dr;//we must use the catch to identify a wrong indextry{//if this event is called from Update
dr = myDataSet.Tables[0].Rows[e.Item.ItemIndex];}catch{//if the event is called from Insert
myDataSet.Tables[0].Rows.InsertAt( myDataSet.Tables[0].NewRow(), myDataSet.Tables[0].Rows.Count);
dr = myDataSet.Tables[0].Rows[e.Item.ItemIndex];}

You can download the sources here* All this article was written using only Freeware applications: ASP.NET Web Matrix for writing and testing the page, Notepad++ for writing the XML file, Gimp for screenshots.

Encryption in .NET Framework is a little tricky… not just create an object and call Encrypt and Decrypt methods, but terms like CryptoServiceProvider, CipherMode, IV and so on…Most of the examples that i found on the internet treats file encryption instead of text encryption (which i’m interested in).
These days i found a very useful article about text encryption written by Chidi C. Ezeukwu. Based on it i wrote a class for encryption/decryption with RC2 algorythm. This class can be used stand-alone in the application or as an assembly.

Search

About me.

I am Senior Technologist for Oracle Corp., delivering workshops, presentations and working in projects for EMEA partners. I have a degree in Software Engineering and own OCP DBA, OCP Dev and MCSD certifications.