Oracle Specific .Net Provider VS .Net Oledb Provider

•May 3, 2007 • Leave a Comment

It is a fairly common practice to utilize the Ole db providers.  They are pretty straight forward to use and can connect to  most databases (sql server, oracle, mysql, db2, access, excell, txt files).

Generic provider, while useful, do not provide optimizations that specific data providers do.  This is the case of the Oracle dataprovider for .Net. When working with Oracle databases,  there is an significant advantage of using the Oracle spefic .net data provider.  According to Gregory Leake in his article Using .NET Framework Data Provider for Oracle to Improve .NET Application Performance the perfomance boost is up to 200% in the Oracle specific provider. 

There are to Oracle specif providers that i know:
- Oracle ODP.Net
- Microsoft .Net Managed provider for Oracle
Feel free to try out any of them.

Happy Blogging!!

My CodeProjects articles

•May 3, 2007 • Leave a Comment

Well so far i got one article published in this site. More to come !!!

http://www.codeproject.com/asp/DataLinkDialog.asp

Happy Blogging!!

DatagridView Custom Cell Styling

•May 3, 2007 • 3 Comments

Last week, I came across this issue. How to change the style of particular cells.  Being .net 2.0 I thought this would as easy as locating the cell i wanted to change the style, change the background, invalidate the cell and that was it. 

 Well, for my surprise it didnt turn out to be like that.  I kept running tests and verifying that my code was correct, wondering why the cell background didnt change.    It didnt make sense to me, that this apparently easy issue would take longer than expected.

 Well, after some research, I found out there are two ways of doing this correctly. 

- Creating custom cell class and custom column class for the datagridview.

- Implementing a handler for the DataGridViewCellPainting event.

Creating two custom classes just to change the background color or font type of the cell seems like too much overhead. So I will cover the latter method, since is easier to implement. 

 First, we need to understand a couple of things.

- If this event doesn’t get implement the control would follow its normal rendering of the cell. So we always need a condition to distinct the cell we want to customized.  

- Since we need to implement our painting fucntionality, we need to be cautious when writing the text content back to the cell. Check for DBNull values as well as for null values, also ensure to explicitly cast the value of the cell using the Convert function. 


//Condition to locate the cell we want to customized
if (e.RowIndex == 0 && e.ColumnIndex == 1)
{
//String format required to align to the text to the right inside the cell
StringFormat format = new StringFormat(StringFormat.GenericDefault);
format.Alignment = StringAlignment.Far;
format.LineAlignment = StringAlignment.Center;
format.Trimming = StringTrimming.EllipsisCharacter;
Rectangle newRect = new Rectangle(e.CellBounds.X + 1,
e.CellBounds.Y + 1, e.CellBounds.Width - 4,
e.CellBounds.Height - 4);
e.CellStyle.BackColor = Color.LightSkyBlue;
using (
Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),
backColorBrush = new SolidBrush(e.CellStyle.BackColor))
{
using (Pen gridLinePen = new Pen(gridBrush))
{
// Erase the cell.
e.Graphics.FillRectangle(backColorBrush, e.CellBounds);

// Draw the grid lines (only the right and bottom lines;
// DataGridView takes care of the others).
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
e.CellBounds.Bottom - 1);
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
e.CellBounds.Top, e.CellBounds.Right - 1,
e.CellBounds.Bottom);

// Draw the text content of the cell, right alignment
if (e.Value != null || e.Value != DBNull.Value)
{

e.Graphics.DrawString( Convert.ToString(e.FormattedValue),
e.CellStyle.Font, Brushes.Black, e.CellBounds,
format);
}
e.Handled = true;
}
}

}
So far, this example will just change the background color of the cell. But it is possible to further customized the cell. These changes while interesting are out of the scope of this post.

Happy Blogging!!

Multiple Columns sorting for DataGridView

•May 3, 2007 • Leave a Comment

DataView are useful way of binding data to a datagrid.   It’s common knowledge that they have a sort property.  It is also interesting that through this sort property one can sort multiples columns.    

tView.Sort = "Issuer ASC, Coupon ASC, Maturity ASC";
myDataGrid.DataSource = tViewSort;

The good old dataview not only sorts the multiple columns it also sorts new rows added to the datagrid on runtime. Pretty usefull stuff one might say.

Hello Bloggers

•May 3, 2007 • 3 Comments

Hello Bloggers!!

This is a humble attempt to express ideas, approaches, frustrations and solutions of a young programmer with .net 2.0 and up.   (WPF and others).

Hopefully, this blog would be as helpful for me and some of you.