Jul 27, 2009

Add Serial number in Crystal Report - Not through code

Crystal Report :

Adding a serial number in grouping without any code. I have placed the step by step screenshots which will explain easily how to do it.

1) Add a new field in Running Total Fields in Field Explorer

2) Give a proper name to your Running total name. For example I have choosen here RTotal1. Now categorize based on which field in database you want to summarize it. Next is as we want serial number select count. If you want your serial number to start again from the start when the value in the group changes then select on change of group and specify the grouping name else keep the default value.

3) Smaple Preview of the Design View of Report where I Have added SRNo column at the start in grouping section.

Jul 23, 2009

Job Interview questions and answers - SQL Server 2008

Job Interview questions

1)What is RDBMS?

Relational Data Base Management Systems (RDBMS) are database management systems that maintain data records and indices in tables. Relationships may be created and maintained across and among the data and tables. In a relational database, relationships between data items are expressed by means of tables. Interdependencies among these tables are expressed by data values rather than by pointers. This allows a high degree of data independence. An RDBMS has the capability to recombine the data items from different files, providing powerful tools for data usage.

2)What are the properties of the Relational tables?
Relational tables have six properties:
Values are atomic.
Column values are of the same kind.
Each row is unique.
The sequence of columns is insignificant.
The sequence of rows is insignificant.
Each column must have a unique name.

3)What is Normalization?
Database normalization is a data design and organization process applied to data structures based on rules that help building relational databases. In relational database design, the process of organizing data to minimize redundancy is called normalization. Normalization usually involves dividing a database into two or more tables and defining relationships between the tables. The objective is to isolate data so that additions, deletions, and modifications of a field can be made in just one table and then propagated through the rest of the database via the defined relationships.

4)What are different normalization forms?
1NF: Eliminate Repeating Groups
Make a separate table for each set of related attributes, and give each table a primary key. Each field contains at most one value from its attribute domain.

2NF: Eliminate Redundant Data
If an attribute depends on only part of a multi-valued key, remove it to a separate table.

3NF: Eliminate Columns Not Dependent On Key
If attributes do not contribute to a description of the key, remove them to a separate table. All attributes must be directly dependent on the primary key.

BCNF: Boyce-Codd Normal Form
If there are non-trivial dependencies between candidate key attributes, separate them out into distinct tables.

4NF: Isolate Independent Multiple Relationships
No table may contain two or more 1:n or n:m relationships that are not directly related.

5NF: Isolate Semantically Related Multiple Relationships
There may be practical constrains on information that justify separating logically related many-to-many relationships.

ONF: Optimal Normal Form
A model limited to only simple (elemental) facts, as expressed in Object Role Model notation.

DKNF: Domain-Key Normal Form
A model free from all modification anomalies is said to be in DKNF.
Remember, these normalization guidelines are cumulative. For a database to be in 3NF, it must first fulfill all the criteria of a 2NF and 1NF database.

5)What is De-normalization?
De-normalization is the process of attempting to optimize the performance of a database by adding redundant data. It is sometimes necessary because current DBMSs implement the relational model poorly. A true relational DBMS would allow for a fully normalized database at the logical level, while providing physical storage of data that is tuned for high performance. De-normalization is a technique to move from higher to lower normal forms of database modeling in order to speed up database access.

6)What is Stored Procedure?
A stored procedure is a named group of SQL statements that have been previously created and stored in the server database. Stored procedures accept input parameters so that a single procedure can be used over the network by several clients using different input data. And when the procedure is modified, all clients automatically get the new version. Stored procedures reduce network traffic and improve performance. Stored procedures can be used to help ensure the integrity of the database.
e.g. sp_helpdb, sp_renamedb, sp_depends etc.

7)What is Trigger?
A trigger is a SQL procedure that initiates an action when an event (INSERT, DELETE or UPDATE) occurs. Triggers are stored in and managed by the DBMS. Triggers are used to maintain the referential integrity of data by changing the data in a systematic fashion. A trigger cannot be called or executed; DBMS automatically fires the trigger as a result of a data modification to the associated table. Triggers can be viewed as similar to stored procedures in that both consist of procedural logic that is stored at the database level. Stored procedures, however, are not event-drive and are not attached to a specific table as triggers are. Stored procedures are explicitly executed by invoking a CALL to the procedure while triggers are implicitly executed. In addition, triggers can also execute stored procedures.

Nested Trigger: A trigger can also contain INSERT, UPDATE and DELETE logic within itself, so when the trigger is fired because of data modification it can also cause another data modification, thereby firing another trigger. A trigger that contains data modification logic within itself is called a nested trigger. (Read More Here)

8)What is View?
A simple view can be thought of as a subset of a table. It can be used for retrieving data, as well as updating or deleting rows. Rows updated or deleted in the view are updated or deleted in the table the view was created with. It should also be noted that as data in the original table changes, so does data in the view, as views are the way to look at part of the original table. The results of using a view are not permanently stored in the database. The data accessed through a view is actually constructed using standard T-SQL select command and can come from one to many different base tables or even other views.

9)What is Index?
An index is a physical structure containing pointers to the data. Indices are created in an existing table to locate rows more quickly and efficiently. It is possible to create an index on one or more columns of a table, and each index is given a name. The users cannot see the indexes; they are just used to speed up queries. Effective indexes are one of the best ways to improve performance in a database application. A table scan happens when there is no index available to help a query. In a table scan SQL Server examines every row in the table to satisfy the query results. Table scans are sometimes unavoidable, but on large tables, scans have a terrific impact on performance.

10)What is a Linked Server?
Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements. With a linked server, you can create very clean, easy to follow, SQL statements that allow remote data to be retrieved, joined and combined with local data. Stored Procedure sp_addlinkedserver, sp_addlinkedsrvlogin will be used add new Linked Server

Jul 22, 2009

Create your own Input Box

Windows Forms : Input box

Simple code to create your own Input-box.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

/// Summary description for frmInputBox.

public class frmInputBox : System.Windows.Forms.Form
private string _title = "Title";
private string _prompt = "Please enter in a value:";
private string _inputValue = string.Empty;

private System.Windows.Forms.Label lblPrompt;
private System.Windows.Forms.TextBox txtInput;
private System.Windows.Forms.Button cmdOK;
private System.Windows.Forms.Button cmdCancel;

/// Required designer variable.

private System.ComponentModel.Container components = null;

public frmInputBox()
// Required for Windows Form Designer support


public frmInputBox(string prompt, string title, string inputValue)
// Required for Windows Form Designer support

this._title = title;
this._prompt = prompt;
this._inputValue = inputValue;


private void SetValues()
this.Text = this._title;
this.lblPrompt.Text = this._prompt;
this.txtInput.Text = this._inputValue;

/// Clean up any resources being used.

protected override void Dispose( bool disposing )
if( disposing )
if(components != null)
base.Dispose( disposing );

#region Windows Form Designer generated code
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.

private void InitializeComponent()
this.lblPrompt = new System.Windows.Forms.Label();
this.txtInput = new System.Windows.Forms.TextBox();
this.cmdOK = new System.Windows.Forms.Button();
this.cmdCancel = new System.Windows.Forms.Button();
// lblPrompt
this.lblPrompt.Location = new System.Drawing.Point(8, 8);
this.lblPrompt.Name = "lblPrompt";
this.lblPrompt.Size = new System.Drawing.Size(344, 56);
this.lblPrompt.TabIndex = 0;
this.lblPrompt.Text = "Please enter in a value:";
// txtInput
this.txtInput.Location = new System.Drawing.Point(8, 80);
this.txtInput.Name = "txtInput";
this.txtInput.Size = new System.Drawing.Size(416, 20);
this.txtInput.TabIndex = 1;
this.txtInput.Text = "";
// cmdOK
this.cmdOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.cmdOK.Location = new System.Drawing.Point(360, 8);
this.cmdOK.Name = "cmdOK";
this.cmdOK.TabIndex = 2;
this.cmdOK.Text = "OK";
this.cmdOK.Click += new System.EventHandler(this.cmdOK_Click);
// cmdCancel
this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cmdCancel.Location = new System.Drawing.Point(360, 40);
this.cmdCancel.Name = "cmdCancel";
this.cmdCancel.TabIndex = 3;
this.cmdCancel.Text = "Cancel";
this.cmdCancel.Click += new System.EventHandler(this.cmdCancel_Click);
// frmInputBox
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(440, 109);
this.KeyPreview = true;
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(448, 136);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(448, 136);
this.Name = "frmInputBox";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Title";
this.Activated += new System.EventHandler(this.frmInputBox_Activated);
this.KeyDown += new KeyEventHandler(frmInputBox_KeyDown);


private void frmInputBox_Activated(object sender, EventArgs e)

private void cmdOK_Click(object sender, System.EventArgs e)
this._inputValue = txtInput.Text;

private void cmdCancel_Click(object sender, System.EventArgs e)

public string InputValue
get { return this._inputValue; }
set { this._inputValue = value; }

public string Title
get { return this._title; }
set { this._title = value; }

public string Prompt
get { return this._prompt; }
set { this._prompt = value; }

public static string InputBox(string prompt, string title, string inputValue)
string retVal = string.Empty;

frmInputBox frm = new frmInputBox(prompt, title, inputValue);
if(frm.ShowDialog() == DialogResult.OK)
retVal = frm.InputValue;


return retVal;

private void frmInputBox_KeyDown(object sender, KeyEventArgs e)
if(e.KeyData == Keys.Enter)
cmdOK_Click(sender, EventArgs.Empty);
else if(e.KeyData == Keys.Escape)
cmdCancel_Click(sender, EventArgs.Empty);

Create Salt/IV file for password

This code demonstrates that the salt and initialization vector (IV) are persisted unencrypted to a .dat file. In this way you can see how you would securely send a document to someone: The encrypted document could be sent over an unsecure wire, and the .dat file and password could be transferred securely using assymetric (or, public key) encryption.

using System.Text.RegularExpressions;
using System.Security.Cryptography;

private SampleCrypto crpSample;

This routine handles the "Create Salt / IV Key" button click event.

private void btnCreateKey_Click(object sender, System.EventArgs e)
try {
if (PasswordIsValid())
crpSample.Password = txtPassword.Text;

if (crpSample.CreateSaltIVFile(strCurrentKeyFile))
MessageBox.Show("Salt and IV successfully generated and saved to a .dat " + Environment.NewLine +
"file in the Visual Studio .NET Solution root folder.",
catch( Exception exp)
MessageBox.Show(exp.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);

This routine validates the password.

private bool PasswordIsValid()
if (!Regex.IsMatch(txtPassword.Text, @"^\s*(\w){8}\s*$"))
MessageBox.Show("You must enter an 8-digit password consisting of numbers " +
"and/or letters.", this.Text,MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;

return true;

This routine creates a .dat file containing the salt and IV.

public bool CreateSaltIVFile(string strSaveToPath)
// Initialize the byte arrays to the proper length for the
// instantiated crypto class.


// Create a Filestream object to write the salt and IV to a file.

FileStream fsKey = new FileStream(strSaveToPath, FileMode.OpenOrCreate,

// Generate a random "salt" value.
RandomNumberGenerator rng = RandomNumberGenerator.Create();


PasswordDeriveBytes pdb = new PasswordDeriveBytes(strPassword, abytSalt);

// Get the same amount of bytes the current abytKey length set in
// ReDimByteArrays().

abytKey = pdb.GetBytes(abytKey.Length);

// Generate a new random IV.

abytIV = crpSym.IV;

fsKey.Write(abytSalt, 0, abytSalt.Length);
fsKey.Write(abytIV, 0, abytIV.Length);
strSaltIVFile = strSaveToPath;
return true;
catch( Exception exp)
throw new Exception(exp.Message);

This routine redimensions the byte arrays to the proper length for the instantiated crypto class.

private void ReDimByteArrays()
// For testing purposes only, write out the legal key sizes.

Debug.WriteLine(crpSym.GetType().ToString() + " legal key sizes in bits:");

foreach(KeySizes myKeySizes in crpSym.LegalKeySizes)
Debug.WriteLine("Max=" + myKeySizes.MaxSize + " bits " +
"(" + (myKeySizes.MaxSize / 8) + " bytes)");

Debug.WriteLine("Min=" + myKeySizes.MinSize + " bits " +
"(" + (myKeySizes.MinSize / 8) + " bytes)");

Debug.WriteLine("Skip=" + myKeySizes.SkipSize + " bits " +
"(" + (myKeySizes.SkipSize / 8) + " bytes)");
if (crpSym.GetType() == typeof(System.Security.Cryptography.RijndaelManaged))
// The Key byte array size was retrieved via the LegalKeySizes property
// of the crypto object.
abytKey = new byte[31];
// A good rule-of-thumb is to make the salt 1/2 the length of the key.
abytSalt = new byte[15];
abytIV = new byte[15];
abytKey = new byte[23];
abytSalt = new byte[11];
abytIV = new byte[7];

Jul 21, 2009

Alt+ Shortcut keys

Alt+ Shortcut keys :

Have you ever Wondered how someone makes a Heart, Arrow or even a TM trademark symbol with their Keyboard?

All you need to do is Hold down your "ALT" key and press another key on the keyboard to create a symbol.

Here is a list of some you can make. Have Fun!!

· Alt + 0153 - Trademark symbol
· Alt + 0169 - Copyright symbol
· Alt + 0174 - Registered trademark symbol
· Alt + 0176 - Degree symbol
· Alt + 0177 - Plus-or-minus sign
· Alt + 0182 - Paragraph mark
· Alt + 0190 - Fraction, three-fourths
· Alt + 0215 - Multiplication sign
· Alt + 0162 - The cent sign
· Alt + 0161 - Upside down exclamation point
· Alt + 0191 - Upside down question mark
· Alt + 1 - Smiley fsce
· Alt + 2 - Black smiley face
· Alt + 15 - Sun
· Alt + 12 - Female sign
· Alt + 11 - Male sign
· Alt + 6 - Spade sign
· Alt + 5 - Club symbol
· Alt + 3 - Heart
· Alt + 4 - Diamond
· Alt + 13 - Eighth note
· Alt + 14 - Beamed eighth note
· Alt + 8721 - N-ary summation (auto sum)
· Alt + 251 - Square root check mark
· Alt + 8236 - Infinity
· Alt + 24 - Up arrow
· Alt + 25 - Down arrow
· Alt + 26 - Right pointing arrow
· Alt + 27 - Left arrow
· Alt + 18 - Up/down arrow
· Alt + 29 - Left right arrow

Jul 7, 2009

An Editor Now!!!!

Today again a wonderful day as I am now a Editor of DotNetSpider(DNS).

For More details visit :