Always Get Better

Never stop looking for ways to improve

April 11th, 2008

Being used to SQL Server, I get messed up when moving to Oracle. For reference, here are equivalent top N queries in both environments:

SQL Server:

SELECT TOP 10 book_name, price*sales
FROM tblBooks;

Oracle:

SELECT book_name, price*sales
FROM tblBooks
WHERE ROWNUM <= 10;

April 6th, 2008

By default, SQL Server doesn’t allow an operation like this:

SELECT SUM(blnBitColumn) FROM tblTable;

In order to achieve this result, you must first convert the bit column to a numeric type:

SELECT SUM(CONVERT(int,blnBitColumn)) FROM tblTable;

This counts the number of times the bit is true.

If you want to get the flip-side of that to see how many times the bit is false, just subtract the total number of bits from the positive:

SELECT COUNT(blnBitColumn)-SUM(CONVERT(int,blnBitColumn)) FROM tblTable;

April 5th, 2008

The project I am currently working on has several dozen different types of Form classes, each of which is accessible from a common menu strip. Rather than repeatedly instantiating each of the forms from the menu item handlers, I wanted to funnel the request to a single function.

The problem is: How do you instantiate a form when the type is unknown?

The code snippet is:

CreateForm( typeof(CustomFormType) );

Form CreateForm( Type formType )
{
return (Form)Activator.CreateInstance(formType);
}

April 4th, 2008

When working with a Windows GUI, it may seem unclear whether to use Form.Close() or Form.Dispose() to get rid of a dialog at runtime.

Form.Close() removes the dialog from sight and calls the Closing() and Closed() methods.  You can still access the form and bring it back later on.

Form.Dispose() destroys the dialog and frees its resources back to the operating system.   It does not call the form’s Closing() and Closed() methods. Once disposed, you may not recall a form.

Which to use? If you have no logic in the form’s close methods and don’t intend to re-use the form, go with Dispose().  Otherwise, go with Close().  Some programmers aren’t sure which to use, and they use both – Close() then Dispose()!

April 3rd, 2008

In order to change my password on a remote Windows 2003 server, I recently needed to send a Ctrl+Alt+Del sequence to the host. By default, doing this sends that sequence to your own machine.

To send the command to the hosting server, type Ctrl+Alt+End.