Monday, November 17, 2008

Set Password Textbox value dynamically

Set Password Textbox value dynamically
Usually when we need to set values for textboxes dynamically, we just assign values to the Textbox's Text property like,

TextBox1.Text = "hsp";

But the above statement will not work, if the Textbox mode is "Password".
Suppose we want to set the values of Password mode textbox, we can use the following code.

TextBox1.Attributes["value"] = "hsp";


Also, when the page is getting postback, the values in Password textboxes will be cleared. But you can retain the text in password textboxes.
Add the following code in Page_Load event of the page.

TextBox1.Attributes.Add("value", TextBox1.Text);

Friday, November 14, 2008

Find N-th highest record in SQL Server

Find N-th highest record in SQL Server
The following list of queries can be used to get N-th maximum record from table in SQL Server.
Here, let we consider a simple employee table. And we need to get the employee details whose salary is the 2nd maximum of the table.

Option: 1

Select top 1 * from employee where salary not in (select max(salary) from employee ) order by salary desc

Option:2

Select top 1 * from (select top 2 * from employee order by salary desc) emp order by emp.salary

Option: 3

Select * from employee e1 where 1 = (select count(distinct(e2.salary)) from employee e2 where e2.salary > e1.salary)

Friday, November 7, 2008

Build components (dll) into Multiple Locations

Build components (dll) into Multiple Locations
Usually when we build a component (dll), the result dll will be stored in path which is specified in OutputPath of that project Properties.
output Path

By default the output path is “bin\debug” of the particular project.
We can change this path to our required one.

Suppose, in some solutions, we may use the same dll more than one projects. For this, we need to copy the dll and paste in specific location. This may cause some problem if we forgot to copy and paste. So, we need some automatic process for this.

Thank fully Visual studio provides a concept called Build Events.
Build Events

In that, we can include some DOS command through Macros. The Macros contains some default keys which has values like Target path etc..
Macros

Here For example I want to stored the dll into “d:\test\” folder, we need to add XCOPY command with macros.
Xcopy

xcopy "$(TargetPath)" "d:\test\" /d /y

XCopy Syntax




Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
[/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
[/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
[/EXCLUDE:file1[+file2][+file3]...]

source Specifies the file(s) to copy.
destination Specifies the location and/or name of new files.
/A Copies only files with the archive attribute set,
doesn't change the attribute.
/M Copies only files with the archive attribute set,
turns off the archive attribute.
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
/EXCLUDE:file1[+file2][+file3]...
Specifies a list of files containing strings. Each string
should be in a separate line in the files. When any of the
strings match any part of the absolute path of the file to be
copied, that file will be excluded from being copied. For
example, specifying a string like \obj\ or .obj will exclude
all files underneath the directory obj or all files with the
.obj extension respectively.
/P Prompts you before creating each destination file.
/S Copies directories and subdirectories except empty ones.
/E Copies directories and subdirectories, including empty ones.
Same as /S /E. May be used to modify /T.
/V Verifies each new file.
/W Prompts you to press a key before copying.
/C Continues copying even if errors occur.
/I If destination does not exist and copying more than one file,
assumes that destination must be a directory.
/Q Does not display file names while copying.
/F Displays full source and destination file names while copying.
/L Displays files that would be copied.
/G Allows the copying of encrypted files to destination that does
not support encryption.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/T Creates directory structure, but does not copy files. Does not
include empty directories or subdirectories. /T /E includes
empty directories and subdirectories.
/U Copies only files that already exist in destination.
/K Copies attributes. Normal Xcopy will reset read-only attributes.
/N Copies using the generated short names.
/O Copies file ownership and ACL information.
/X Copies file audit settings (implies /O).
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
/-Y Causes prompting to confirm you want to overwrite an
existing destination file.
/Z Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.


After adding the command line save the build Events.

Build Events added

Now Build your dll. The dll will be stored in “bin/debug” path of the project folder and also in “d:\test\” folder. (Make sure d: drive should contain test folder. Otherwise it gives an error)