A personal repository of technical notes. - CSC

Expose Custom Control Sub-Property to Intellisense

// Exposes subproperties to intellisense

using System.ComponentModel;

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Literal MyLiteral
{
get { return myLiteral; }
set { myLiteral = value; }
}

// So that the following will show up in intellisense of control in front end:
MyLiteral-Text=""

SQL Conditional Sorting with Dynamic ORDER BY

Dynamic SQL Sorting with ORDER BY
  

DECLARE @sortByColumn varchar(100)

SELECT @sortByColumn = 'MyColumn05'-- 'MyColumn01'-- 'X'--

-- Dynamic Sorting Column in SELECT

SELECT

MyColumn01

,MyColumn02

,(MyColumn03 * MyColumn04)

,MyColumn05

,CASE @sortByColumn

WHEN 'MyColumn01' THEN MyColumn01

WHEN 'MyColumn02' THEN MyColumn02

WHEN 'MyColumn05' THEN STR(MyColumn05,19,16)

ELSE MyColumn01

END AS SorterColumn

FROM MyTableA

ORDER BY SorterColumn

-- Dynamic Sorting Column in ORDER BY

SELECT

MyColumn01

,MyColumn02

,(MyColumn03 * MyColumn04) AS NewColumn -- Calculation duplicated below in ORDER BY

,MyColumn05

FROM MyTableA

ORDER BY

CASE @sortByColumn

WHEN 'MyColumn01' THEN MyColumn01

WHEN 'MyColumn02' THEN MyColumn02

WHEN 'NewColumn' THEN STR(MyColumn03 * MyColumn04) -- Calculation duplicated above in SELECT

WHEN 'MyColumn05' THEN STR(MyColumn05,19,16)

ELSE MyColumn01

END

SELECT

MyColumn01

,MyColumn02

FROM MyTableA

ORDER BY

CASE

WHEN MyColumn01 > 0 THEN 0

ELSE 1

END

,MyColumn02

--------------------------------------------------

DECLARE @sortDesc bit

SELECT @sortDesc = 1-- 0--

-- Dynamic DESCENDING / ASCENDING

SELECT AsOfDate,MyColumn01,MyColumn05

FROM MyTableA

WHERE AsOfDate = '7-31-2007'

ORDER BY

CASE WHEN @sortDesc = 0 THEN MyColumn01 END ASC,

CASE WHEN @sortDesc = 1 THEN MyColumn01 END DESC

-- Dynamic DESCENDING / ASCENDING with Dynamic Sorting Column in ORDER BY

SELECT

MyColumn01

,MyColumn02

,(MyColumn03 * MyColumn04) AS NewColumn -- Calculation duplicated below in ORDER BY

,MyColumn05

FROM MyTableA

LEFT OUTER JOIN MyTableB

ON FM_TICKER = MyColumn01

WHERE AsOfDate = '7-31-2007'

ORDER BY

-- Ascending Sorts

CASE WHEN @sortDesc = 0 AND @sortByColumn = 'MyColumn01' THEN MyColumn01 END ASC,

CASE WHEN @sortDesc = 0 AND @sortByColumn = 'MyColumn02' THEN MyColumn02 END ASC,

CASE WHEN @sortDesc = 0 AND @sortByColumn = 'NewColumn' THEN STR(MyColumn03 * MyColumn04) END ASC, -- Calculation duplicated above in SELECT

CASE WHEN @sortDesc = 0 AND @sortByColumn = 'MyColumn05' THEN STR(MyColumn05,19,16) END ASC,

-- Descending Sorts

CASE WHEN @sortDesc = 1 AND @sortByColumn = 'MyColumn01' THEN MyColumn01 END DESC,

CASE WHEN @sortDesc = 1 AND @sortByColumn = 'MyColumn02' THEN MyColumn02 END DESC,

CASE WHEN @sortDesc = 1 AND @sortByColumn = 'NewColumn' THEN STR(MyColumn03 * MyColumn04) END DESC, -- Calculation duplicated above in SELECT

CASE WHEN @sortDesc = 1 AND @sortByColumn = 'MyColumn05' THEN STR(MyColumn05,19,16) END DESC

-- WARNING: Dynamic DESCENDING / ASCENDING **DOES NOT WORK** with Dynamic Sorting Column in SELECT

SELECT AsOfDate,MyColumn01,MyColumn05

,CASE @sortByColumn

WHEN 'MyColumn01' THEN MyColumn01

WHEN 'MyColumn05' THEN STR(MyColumn05,19,16)

END AS SorterColumn

FROM MyTableA

WHERE AsOfDate = '7-31-2007'

ORDER BY

CASE WHEN @sortDesc = 0 THEN SorterColumn END ASC,

CASE WHEN @sortDesc = 1 THEN SorterColumn END DESC

Visual Studio Remove Recent Projects MRU

Problem
Need to remove obsolete items from most recently used (MRU) Project items in Visual Studio.

Solution
To clear mru project list in Visual Studio
  1. Exit out of Visual Studio.
  2. Find entries located in registry location:
    VS2005: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\ProjectMRUList
    VS2008: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\ProjectMRUList
  3. Change unwanted entries to "DELETEME".
  4. Open Visual Studio
  5. Click on entries labeled "DELETEME" under "Recent Projects".
  6. Select "Yes" when asked to remove entry.
References
None

Updates
2011-01-21 Added VS2008 location.
2010-09-08 Changed removal procedure.

SSMS Connect to Server Server Name List

Problem
How do you remove the server name entries from the Connect to Server dialog box in Microsoft SQL Server Management Studio?

Solution for SSMS 2005
Delete the entire MRU list while SSMS is not running. When it starts up again, a new empty list will be created. As of this posting, I know of no way to remove individual items. MRU location:
%APPDATA%\Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat

Solution for SSMS 2008
Delete the entire settings file while SSMS is not running. WARNING: This file contains other settings.
%APPDATA%\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin

References
About The Connect to Server Dialog - MSDN Forums
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=146430&SiteID=1

SQL Server Forums - SSMS drop down
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=72477

How to get rid of unused servers in SSMS? - TechNet Forums
http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=532146&SiteID=17

SSMS Default Database

To set default database for Microsoft SQL Server Management Studio:

1) On "Connect to Server" dialog box, click button "Options >>"
2) Under "Connection Properties" tab, select the name of the database for the connection.

.NET 2.0 Type.GetType (String) Returns NULL

Problem
Type.GetType (String, true) throws the following error:
Could not load type 'MyType' from assembly 'MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

Solution
String needs to be the assembly-qualified name of the Type:
MyType.GetType().AssemblyQualifiedName


References
Haibo Luo's weblog : Type.GetType(string typeName) returns null !?
http://blogs.msdn.com/haibo_luo/archive/2005/08/21/454213.aspx

Type.GetType Method (String) (System)
http://msdn.microsoft.com/en-us/library/w3f99sx1(VS.80).aspx

CSS Indentation

<div style="padding-left:30px;">This is indented.</div>
<span style="padding-left:30px;">This is indented.</span>
<div class="Indent"></div>
<span class="Indent"></span>
<span style="margin-left:3em; text-indent:-3em;">A hanging indent.</span>
<span class="hang"></span>
<b>Updates</b>
<div class="hang">YYYY-MM-DD Added "Xxx"</div>

<div class="EdNote">Note</div>

JavaScript Enum Emulator

var pageState = {
Normal : 0 ,Autoloading : 1 ,AutoloadStopping : 2
} var myPageStage = pageState.Normal; alert(myPageStage);
References
How to do enumerations (enum) in javascript | Javascript Kata
http://www.javascriptkata.com/2007/03/22/how-to-do-enumerations-enum-in-javascript/

How to use anonymous objects | Javascript Kata
http://www.javascriptkata.com/2007/03/22/how-to-use-anonymous-objects/

Custom Command Prompt Prompt

How to make a custom 2 line command prompt for all command prompts in Windows

Example

C:\WINDOWS\system32
> _


Steps

  1. Right-click My Computer
  2. Properties
  3. Advanced system settings
  4. Environment Variables button
  5. New button under User variables for My User Name
  6. Variable name: PROMPT
  7. Variable value: $P$_$G$S
  8. OK
Notes
Where $P$_$G$S is
$p = Current drive and path
$_ = ENTER-LINEFEED
$g = > (greater-than sign)
$s = space
Note: Tested in Windows 7, Windows Server 2008, Windows XP.

References
Prompt
http://technet.microsoft.com/en-us/library/bb490977.aspx

Determine .NET Version

Updated 2011-10-17
1) In the Registry Editor, locate the Registry Key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\
2) Compare settings to table on Microsoft site:
Old Method
1) View properties version tab of mscorlib.dll in .NET framework folder.
Example:
C:\WINNT\Microsoft.NET\Framework\v1.1.4322\mscorlib.dll
File version: 1.1.4322.2032

2) Match up to Microsoft's list:

The released versions of the .NET Framework have the following version information.

Collapse this tableExpand this table
.NET Framework versionRevisionVersion
3.5Original release3.5.21022.8
3.5Service Pack 13.5.30729.1
3.0Original release3.0.4506.30
3.0Service Pack 13.0.4506.648
3.0Service Pack 23.0.4506.2152
2.0Original release2.0.50727.42
2.0Service Pack 12.0.50727.1433
2.0Service Pack 22.0.50727.3053
1.1Original release1.1.4322.573
1.1Service Pack 11.1.4322.2032
1.1Service Pack 1 (Windows Server 2003 32-bit version*)1.1.4322.2300
1.0Original release1.0.3705.0
1.0Service Pack 11.0.3705.209
1.0Service Pack 21.0.3705.288
1.0Service Pack 31.0.3705.6018
*The Microsoft .NET Framework 1.1 is included with the 32-bit version of Windows Server 2003.
(Microsoft Help and Support)

See Microsoft's web site below in References for latest list.

References
"How to determine which versions of the .NET Framework are installed and whether service packs have been applied." Microsoft Help and Support. 30 Jan. 2009 http://support.microsoft.com/kb/318785.

DLL Help Database
http://support.microsoft.com/dllhelp/?dlltype=file&l=55α=Mscorlib.dll&S=1&x=10&y=13