Monday, December 3, 2012

Enter key navigation in c#


protected override void OnKeyDown(KeyEventArgs e)

{


if (e.KeyCode == Keys.Enter)

{

SelectNextControl(ActiveControl,true, true, true, true);

 
e.Handled = true;


}

}

Saturday, December 1, 2012

INDEX / MATCH Function in MS Excel Example

One advantage of the INDEX / MATCH functions is that the lookup value can be in any column in the array, unlike the VLOOKUP function, in which the lookup value must be in the first column.

In this INDEX / MATCH example, the MATCH function will find the position of "Jacket" in column B, and the INDEX function will return the code from the same position in column A.

  1. Set up the worksheet as shown at right
  2. Enter the following formula in cell B6:
    =INDEX($A$2:$A$4,MATCH(A6,$B$2:$B$4,0))
  3. Press the Enter key to see the result.

The MATCH function, MATCH(A6,$B$2:$B$4,0), returns 2, which is the position of "Jacket" in the list.

Then, the INDEX function, INDEX($A$2:$A$4,2), returns "JK002", which is the second item in the range $A$2:$A$4.

A
B
1
Code
Item
2
SW001
Sweater
3
JK002
Jacket
4
PN001
Pants
5
6
Jacket
JK002

Wednesday, October 3, 2012

How to enable OPENROWSET and OPENDATASOURCE support in SQL Server 2008

sp_configure  'show advanced options',1

 
reconfigure


sp_configure 'Ad Hoc Distributed Queries',1
 

reconfigure

Sunday, September 16, 2012

Could not open key: UNKNOWN\Components

SQL Server 2008 Setup fails to Install with Error 1402


SQL Server 2008 setup may fail with the following error even though you are running the setup as administrator. You might get these kind of errors in Detail.txt after you cleaned up an failed setup (from Add/Remove Programs) and try to run the setup again.
Error 1402. Could not open key: UNKNOWN\Components\493032C95B52CBD448DD2B5A52C50E9A\3EC761FD7E06AE4499CE52705CF173EA.
System error 5. Verify that you have sufficient access to that key, or contact your support personnel.
Action ended 20:37:24: InstallFinalize. Return value 3.
Note: The above GUID may be different in each case
When you search for the GUID that you see in the error in Registry, it maps to the following key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\
Though you might be running the setup as Administrator you may not be able to access the registry key and it sub keys
Even trying to delete the registry key might fail with the access denied errors
In our case the GUID in the error was pointing to MSXML which was already removed from Add/Remove Programs
There are multiple ways to approach this:
Workaround 1
· Download and install psexec utility from the following link
http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
· Open a command prompt (on Vista/Windows 7/2008) using 'run as administrator' option, for Windows (2000 /XP/2003) Hold down the shift key and right click on command prompt and choose run as.
· In the command prompt Navigate to the folder where PSEXEC is installed.
· Execute the following from the command prompt.
§ psexec -i -s cmd.exe
· This will invoke another command prompt running under ‘Local System’
· Using this command prompt open Registry Editor
Command prompt> regedit
· In registry editor navigate to the following hive
HKLM\Software\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\
· Add the user account used to run the installation under permissions for the above hive and grant ‘Full control’ for that user.
o Click on Advanced
clip_image002
o Under the Advanced security settings for Components choose the user and check the “Replace all existing inheritable permissions…………” check box as shown below and click OK
clip_image002[5]
· Re-run the installation.
Workaround 2
As a workaround for the problem you can run the following command at the command prompt to reset the permissions in registry rather than rebuilding the box
SECEDIT /CONFIGURE /CFG %WINDIR%\INF\DEFLTBASE.INF /DB DEFLTBASE.SDB /VERBOSE /AREAS REGKEYS
Disclaimer: The above command would revert all security settings to the default and thus may be used as a workaround to avoid rebuilding the server.
Workaround 3
Another possible solution is for the ‘Administrator’ account to take ownership of HKEY_LOCAL_MACHINE registry hive. Owner can be found under Permissions->Advanced
Note:
This post should not be treated as the Microsoft’s Recommendation or Resolution to the problem, it is only a workaround which worked in our environment and so we would like to share it.

Sunday, June 24, 2012

Decimal Number to Words in Crystal Report

Simply replace the values with your field:

Towords(truncate(8900.89), 0) + " and " + towords(abs(100 * (truncate(8900.89)- 8900.89)), 0) + " centavos";

result is: eight thousand nine hundred and eighty-nine centavos

Why:
Towords(truncate(8900.89), 0) returns 8900, the "," 0 tells the function to ignore the decimal place.

(abs(100 * (8900.89 - truncate(8900.89)) abs converts it to a positive value always just in case and multiplies the value to be non decimal.

If you have more decimal places you'll have to adjust the 100 multiplier


Extra : With First letter upper case:

UpperCase(Left(Towords(truncate({vwchequereportprint.phAmount}), 0),1)) +
 Right (towords(truncate({vwchequereportprint.phAmount}), 0),
Length (towords(truncate({vwchequereportprint.phAmount}), 0))-1)
+" dollar"+(towords(abs(100 * (truncate({vwchequereportprint.phAmount})-{vwchequereportprint.phAmount})), 0)+ " laari")

Friday, March 23, 2012

How to load a windows form from another windows form as a modal dialog box and put the child form in the center of the parent form?



  private void Form1_Load(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
             form2 .StartPosition = FormStartPosition.CenterParent;
            form2.ShowDialog();
        }

Friday, March 16, 2012

Find the row count in SQL Server tables


SELECT
    [TableName] = so.name,
    [RowCount] = MAX(si.rows)
FROM
    sysobjects so,
    sysindexes si
WHERE
    so.xtype = 'U'
    AND
    si.id = OBJECT_ID(so.name)
GROUP BY
    so.name
ORDER BY
    2 DESC