INNER JOIN Operator :-INNER Join return all rows from the join of left table and right table if there are same data available in both tables if no data will match then it will return nullSELECT * FROM Table_Name_1 INNER JOIN Table_Name_2 WHERE Table_Name_1.Column_Name = Table_Name_2.Column_NameYou can divide your result in group like :- If a table...
SQL Tools(Alias Operator & In Operator)
ALIAS Name for Column :-SELECT Column_Name AS Alias_Name FROM Table_NameALIAS Name for table :-SELECT Column_Name From Table_Name AS Alias_NameALIAS Example :-SELECT p.FirstName,p.LastName, po.OrderIDFROM Persons AS p, Product AS poWHERE p.FirstName='Saurabh' AND p.LastName='Singh' AND po.OrderID > 2Without using AS SELECT p.FirstName,p.LastName,...
SQL - Tools (BETWEEN Operator)
SELECT column_name(s) FROM table_nameWHERE column_name BETWEEN value1 AND value2 SELECT * FROM COILS WHERE COIL_NAME BETWEEN SomeValue1 AND SomeValue2 Between operator is like It will select a row where COIL_NAME has SomeValue1 . Value depends on database to database . Some database will select rows where COIL_NAME has SomeValue1 and where COIL_NAME...
SQL - Tools(Top Clause AND Like Operator)
SELECT TOP 1 FROM Table_NameThis will select 1 row from tableSELECT TOP 1* FROM Table_Name (Select all columns of 1st row)SELECT TOP 2* FROM Table_Name (Select first two rows of table)SELECT TOP 50 PERCENT * FROM Table_Name (Select 50 % rows from table)LIKE OPERATORSELECT column_name(s)FROM table_nameWHERE column_name LIKE patternIF...
SQL - Tools ( INSERT,UPDATE and DELETE Statement)
INSERT INTO table_nameVALUES (value1, value2, value3,...)IF a table Persons contains P_Id,LastName,FirstName,Address,City columns.If you want to insert values then :-INSERT INTO PersonsVALUES (4,'Singh', 'Saurabh', 'Sector-23', 'Gurgaon')IF NOT EXISTS (SELECT * FROM Persons WHERE P_Id = 4)BEGININSERT INTO PersonsVALUES (4,'Singh', 'Saurabh', 'Sector-23',...
SQL - Tools(ORDER BY)
ORDER BY keyword is used for sorting suppose in a table there is a column named first_name.If you want to show the result in ascending order then :-SELECT * FROM Persons WHERE Age >= 25 GROUP BY first_name ASCIf you want to show the result in descending order then :-SELECT * FROM Persons WHERE Age >= 25 GROUP BY first_name DESCBy default it...
SQL - Tools (WHERE, AND, OR Clause)
Where clause is use for filtering like :-SELECT * FROM table_name WHERE column_name (operator) value(operator) :- =, >, <,! and more operators.A Friends table contains firstName, secondName, address, phone_no and firstName values are :- saurabh, sandy, gaurav, somu, saurabh and address column values are :- kanpur, allahabad, delhi, kanpur, varanasi.SELECT...
SQL - Tools....(SELECT Clause)
SELECT :-SELECT * FROM TABLE_NAME this will select whole table If Coils table contains 5 columns p_id, coil_no, coil_width, coil_length, coil_name.Then you have to select coil_width and coil_no like :-SELECT coil_width, coil_length FROM CoilsIf you have to select distinct columns from table like coil_name columns have ABCDE12, ABCD13, ABCD14, ABCD12,...
Visual Studio .Net ShortCut keys
DecreaseFilterLevel : ALT + ,IncreaseFilterLevel : ALT + .GotoBrace : CTRL + ]GotoBraceExtend : CTRL _ SHIFT + ]LineEnd : ENDLineEndExtendColumn : SHIFT + ALT + ENDToggleWordWrap : CTRL + E, CTRL + WScrollLineDown : CTRL + DOWN ARRAYLineDownExtendColumn : SHIFT + ALT + DOWN ARRAYWordDeleteToEnd...
How to implement a progressBar while opening a textFile in an application ?
Make a claas like this one to create ProgressBar :-public class StatusProgressBar : ToolStripProgressBar { #region Private Fields private static StatusProgressBar _instance = null; #endregion #region Constructor private StatusProgressBar() { this.Style = ProgressBarStyle.Blocks; this.Step = 1; } #endregion #region Properties /// ///...
What is Reference counting in COM ?
Reference counting is a memory management technique used to count how many times an object has a pointer referring to it. The first time it is created, the reference count is set to one. When the last reference to the object is nulled, the reference count is set to zero and the object is deleted.Care must be exercised to prevent a context switch from...
What is COM ?
Microsoft’s COM is a technology for component software development. It is a binary standard which is language independent. DCOM is a distributed extension of COM.Microsoft COM (Component Object Model) technology in the Microsoft Windows-family of Operating Systems enables software components to communicate. COM is used by developers to create re-usable...
How can we make Windows API calls in .NET?
Windows API call are not COM based and they are invoked through Platform Invoke Services.StringConversionType is for what type of conversion should take place. Either we can specify Unicode to convert all strings to Unicode values, or Auto to convert strings according to the .NET runtime rules.There are few thumbrules to make API calls :-1:- MethodName...
ShFileOperation not working under Wista and Windows7.
I've used ShFileOperation for file operations but was facing some problems and i was not able to understand then i do googling and found the 'cause' of the problems with the SHFileOperation function in Vista . It turns out that this function is not thread safe under Vista. It works fine with earlier operating systems when used in a multi threading...
How to convert 2d array to 1d array ?
Suppose you to insert or get the values from 1d array using 2d dimensions like :-Insert value at (1,2) and the value is 5 then you have to find the logic to get the index :- Firstly you have to know the size of 2d array here suppose :- (2x3)int xPosition = 1;int yPosition = 2;3 is ySize of 2d array.int 1dIndex = (3*xPosition)+ yPosition ;Insert at...
How to convert 3d array to 1d array ?
Suppose you have to insert a value at (2,1,0) and the value is :-5means firstly you have to find the index through (2,1,0) then you have to insert value 5 at that index .Logic is :-Firstly you must have to know the 3d array size suppose here is (3x2x3).int xPosition = 2;int yPosition = 1;int zPosition = 0;int indexOf1dArray = (xPosition *2*3) + ((yPosition...
What is the difference between .ToString() and Convert.ToString() ?
int value = 3;string stringConversion = value.ToString();string stringConversion = Convert.ToString(value);We can convert the integer “value ” using “value .ToString()” or “Convert.ToString” The basic difference between them is “Convert” function handles NULLS .It handles null exception while “value .ToString()”does not it will throw a NULL reference...
Built-in Code Snippets (C#)
List of built in code snippets -
#if :- Creates a #if directive and a #endif directive.
#region :- Creates a #region directive and a #endregion directive.
~ :- Creates a destructor for the containing class.
checked :- Creates a checked block.
ctor :- Creates a constructor for the containing class.
cw :- Creates a call to Console.WriteLine.
for :-...
Message-Box refreshing issue
I have used many message boxes in my current application but in some places where i used list box,list there when i move messagebox then the back screen is looks like everything is removing or cleaning nothing just refreshing issue, then i look and sort out by sinety testing like i used listView.BeginUpdate(); before dialog box check when i used after...
How to collapse Environmental variables in a path using C# ?
Pass the path if there are environmental variables exist in the path then it will be collapsed into a valid path and return the valid path.Constants :-public const string PATH_SEPARATOR = @"\";public const string ENVIROMENT_VARIABLE_FORMAT = "%{0}%";public static string CollapseEnviromentVariables(string pathString) { string result...
How to allign multiple strings using seperator in C# ?
Constant file.public const char SYMBOL_SPACE_CHARACTER = ' ';public static List AlignText(string[] strings, char seperator) { List formattedStringList = new List(); List ListOfCommaSeperatedStringsInLine = new List(); string[] commaSeperatedStringsArray = null; List maxColumnWidthArray = new List(); //split strings into list of comma seperated...
How to check invalid characters in path using C#
If you create a new folder then there are some characters which are not allowed and any thing in which user have rights to create path then firstly check the invalid characters otherwise your application or program will through an exception.Pass the path or string for which you have to check.public static bool CheckInvalidCharacters(string path){ ...
Delegates in C#
Event - Delegates are the key feature of C#,You can say heart of C#.Look on a example :- Suppose if you have two forms and there is no communication between those even you can't create object to access then how will you send some information.In this tutorial i will teach you how to handle and play with delegates to proper communication.Suppose you...
Generics in C#
Hi everyone..in .net 2.0 we do programming in a very smarter way Generics is the example like if we are using minimum finction to find minimum between two numbers they may be integer,string,object and may be some other data types.Consider the following code :-Returns minimum between two integers.int Min( int a, int b ){if (a < b) return a;else return...
Singleton Pattern
Singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. This is very useful when only there is a need of single object which handles all the actions across the system.This pattern restrict the instantiation to a certain number of objects and this concept is to generalize the systems to operate more efficiently...
What is LINQ?
■ LINQ is a uniform programming model for any kind of data. LINQ enables you to queryand manipulate data with a consistent model that is independent from data sources.■ LINQ is just another tool for embedding SQL queries into code.■ LINQ is yet another data abstraction lay...
Remove special characters from string ?
public override string ToString(){ string specialCharacters = "~!@#$%^&*<()+=`',.?>/\\\""; string[] stringAfterRemovingSpecialCharacters= displayText.Split(specialCharacters .ToCharArray()); return string.Concat(stringAfterRemovingSpecialCharacters...
File/Folder is being used by another process Error?
Hi Friends..Resolved Error - File/Folder is being used by another process As i discussed in my current project i made a self explorer.exe so i accessed all the folders,files .i am doing same behaviour as lioke window explorer.exe. But I was facing a error This file/folder is being used by another process and all that and i face all these errors when...
List with ForEach
List Names = new List(); Names.Add("Saurabh"); Names.Add("Somu"); Names.Add("Sandy"); //For every item in the list, say you want to append the last name "Somu" and print it //WITHOUT ForEach() foreach (string name in Names) { Console.WriteLine(name + " Somu"); } //WITH ForEach Names.ForEach(delegate(string name) { Console.WriteLine(...
Yield Keyword
class Program { static void Main(string[] args) { List Names = new List(); Names.Add("saurabh"); Names.Add("somu"); Names.Add("vivek"); foreach (string item in GetNames(Names)) { Console.WriteLine(item); } } public static IEnumerable GetNames(List...
?? keyword
?? keyword is used to check null.Example using if-else statement:-if (tempString == null){ x = "Null string";} else{ x = tempString ;} Console.WriteLine(x); Example using ?? Keywordstring tempString = null; string x = tempString ?? "Null string"; Console.WriteLine(x); //Prints "Null stri...
Problem about Instances...
Hii..Frends this is very genuine problem.Functionality :-When i was developing Window Explorer control for my application then i just stuck in a problem I had three instances of window - explorer.. One is as similar as Window file explorer by which you can drag drop files and that will open in any editor.(We had given additional functionality like...
How to create FilePropertyDialog like Windows in C#?
#region Enum[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct SHELLEXECUTEINFO { public int cbSize; public uint fMask; public IntPtr hwnd; [MarshalAs(UnmanagedType.LPTStr)] public string lpVerb; [MarshalAs(UnmanagedType.LPTStr)] public...
How many instances are running in my application using C# ?
#region Directivesusing System.text;using System.Threading;using System.Reflection;#endregionpublic class TestApplication { #region Private Fields The default instance private static TestApplication DefValue = new TestApplication (); The system-wide semaphore private Semaphore semaphore; Initial count for the semaphore(Randonm you can...
How to Create a Zip file using C#
public bool CreateZip(string ZipFileName){try{Create an empty zip filebyte[] ZipFolder = new byte[]{100,75,50,16,10,5,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};FileStream fs = File.Create(ZipFileName);fs.Write(ZipFolder , 0, ZipFolder.Length);fs.Flush();fs.Close();fs = null;}catch(Exception ignore){}return tru...
How to open a zip file using C# ?
#region Namespaceusing Shell32;#endregionnamespace TestApplicationToZip{class ZipApplication{public static void Main(string[] args){Create the object of shell.Shell sh = new Shell();Create a namespace and folderItem for the existing folder path.Folder ShellFolder = sh.NameSpace("D:\\saurabh.zip");Folder DirectoryFolder = sh.NameSpace("D:\\Unzipped...
Differences between Connected and disconnected architecture ?
Hii friends,Today one of my frend ask about what approach is better connected or disconnected architecture ..So let me explain more about this problem :-As the nature of HTTP protocol,.Net web applications are always disconnected so your problem is about connected or disconnected data models."connected" data is always faster as compare to "disconnected"...
What do you meant by Containment in C#?
Containment is the replacement of inheritence,no no if inheritance isn’t the right choice,then the answer is containment, also known as aggregation. Rather than saying that an object is an example of another object, an instance of that other object will be contained inside the object. So,instead of having a class look like a string, the class will...
How to handle generic errors in WinApp using C# ?
Pass your exception or error through catch block to this method this will catch your error and show the messagebox regarding that error.Method which take error exception as a parameter and handle that error.public static void LogError(Exception ex){string sourceName = "Application Name";int errorCode = "99";string message = "The application encountered...
What is interface and why we implement interfaces ?
Interface defined by using interface keyword .In visualstudio you can directly add class as a interface its not a class it behaves as a template of the class. Interfaces describe a group of related functionalities that can belong to any class or struct.Interfaces are provided in C# as a replacement of multiple inheritance because C# does not support...
How to combine two images into one image in C#?
using System.Drawing;public static System.Drawing.Bitmap Combine(string[] files){ Create a list for images and read images List images = new List(); Bitmap finalImage = null; try { int width = 0; int height = 0; foreach (string image in files) { create a Bitmap from the file and add it to the list. Bitmap bitmap = new...
Location of opening of dialog boxes(window form) in C#
In my application i used some dialog boxes like about of company some customize message boxes and all that in some dialog boxes I used start position as Center parent but i forget to pass the IWin32Window Owner in show dialog as a parameter regarding that when focus is lost from my application then dialog took desktop as a parent and opens in different...
How to set image resolution and paint it in C# ?
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Drawing.Imaging; public class Form1 : System.Windows.Forms.Form { Constructor. public Form1() { InitializeComponent(); } Initialize all the...
C# Tutorial (Chapter - 1) Introduction about C# and .Net framework(1 :- .Net Plateform)
I :-.Net Plateform :-The Microsoft® .NET platform provides all of the tools and technologies thatyou need to build distributed Web applications. It exposes a languageindependent,consistent programming model across all tiers of an applicationwhile providing seamless interoperability with, and easy migration from,existing technologies. The .NET platform...
C# Tutorials
Hello to all, My next thread is about C#,In my next thread i will divide the C# thread into chapters each chapter will contain all the details about C# and .Net framework its a step by step process so go through to all the thread and please post a comment or email me at saurabhjnumca@gmail.com about this thread please give critics about this thread.If...
How to create a session manager in .Net ?
To create a SessionManager to save User objects in memory. It would be HashMap of HaspMaps.It can be used as:SessionManager MySessionManager= New SessionManager()Student S1 = New Student ("Saurabh");Student S2 = New Student ("Sandeep");Student S3 = New Student ("Deepak");//To create sessionMySessionManager.createSession(S1);MySessionManager.createSession(S2);//SAVING...
Tech-Giant(Jargons.. for Professionals): How to take Screenshot of panel,control and save it in a JPG format ?
How to take Screenshot of panel,control and save it in a JPG format ?
You can create a bitmap of screen and then save it give the stream or fileName and then dispose the object of screenshot.Bitmap theScreenShot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);theScreenShot.Save(stream_or_filename, ImageFormat.Jpeg);theScreenShot.Dispose();Another way to...
Order of Event firing in ASP.Net
Event firing order becomes critically important when you add event handling code to master pages and the content forms based on them. The following events occur when ASP.NET renders a page. I’ve listed these events in the order in which they occur.1 :-Content Page Pre Initializes2 :-Master Page Child Controls Initialize3 :-Content Page Child Controls...
Lambda Expressions in C#
Lambda expressions makes the searching life much easier.Have a look on this example :-public class TestLambdaProgram{ public static void Main( string[] args ) { List names = new List(); names.Add(“Saurabh”); names.Add("Garima"); names.Add(“Vivek”); names.Add(“Sandeep”); string stringResult = names.Find( name =>...
Basics of .Net (What is IL,CLR,CTS,CLS ?)
1: IL(Intermediate Language) :-(IL)Intermediate Language is also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language). All .NET source code is compiled to IL. This IL is then converted to machine code at the point where the software is installed, or at run-time by a Just-In-Time (JIT) compiler. Microsoft Intermediate...
What are different types of JIT ?
In .net there are three type of JIT.JIT compiler is a part of the runtime execution environment.Three JIT are following :-Pre-JIT :- Pre-JIT compiles complete source code into native code in a single compilation cycle. This is done at the time of deployment of the application.Econo-JIT :- Econo-JIT compiles only those methods that are called at runtime....
What is Manifest in .net ?
An assembly manifest contains all the metadata.It means Assembly metadata is stored in Manifest and it needed to specify the assembly's version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes.Some points are given please go through it :-1:- The assembly...
How to view a Assembly of your code (What is ILDASM ?)

When it comes to understanding of internals nothing can beat ILDASM. ILDASM basically converts the whole exe or dll in to IL code. To run ILDASM you have to go to "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin". Note that i had v2.0...
How to copy the text from label in window form at run time ?
Designer view:#region DesignerViewCreate a context menu strip :this.copyPathMenuItem = new System.Windows.Forms.ToolStripMenuItem();this.labelContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.copyPathMenuItem});this.labelContextMenuStrip.Name = "labelContextMenuStrip";this.labelContextMenuStrip.Size = new System.Drawing.Size(100,...
How can I change the Border color of my control ?
public class MyButton : Button { protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); int borderWidth = 1; Color borderColor = Color.Blue; ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, borderColor, borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid,...
How to change the color of Tab Control in c#
Steps :-1. Set the TabControl's DrawMode to OwnerDraw.2. Handle the DrawItem event.private void ChangeColorOFTabControl(object sender, DrawItemEventArgs e){Font TabFont;Brush BackBrush = new SolidBrush(Color.Green); //Set background colorBrush ForeBrush = new SolidBrush(Color.Yellow);//Set foreground colorif (e.Index == this.tabControl1.SelectedIndex){TabFont...
How to set dropdown width according to longest string in C#
If you are using window control then use this method.private void AdjustWidthComboBox_DropDown(object sender, System.EventArgs e){ ComboBox senderComboBox = (ComboBox)sender; int width = senderComboBox.DropDownWidth; Graphics g = senderComboBox.CreateGraphics(); Font font = senderComboBox.Font; int vertScrollBarWidth = (senderComboBox.Items.Count>senderComboBox.MaxDropDownItems)...
How to get the file size like windows file property control ?
//Create an object of FileInfo like :- FileInfo fileObject = new FileInfo(selectedFilename);Int64 fileSize = 0;float sizeOfFile = 0fileSize = fileObject.Length;sizeOfFile = fileObject.Length;private const int FILESIZE_IN_KB = 1024;public const int FILESIZE_IN_MB = 1048576;public const int FILESIZE_IN_GB = 1073741824;public const long FILESIZE_IN_TB...
Sort ListView on column click (like windows folder detail view in xp)

Step :1 Firstly Create the object of listviewcolumn sorter class.private ListViewColumnSorter listviewColumnSorter=new ListViewColumnSorter();Step :2 Set ListViewItemSorter property of listViewlistView.ListViewItemSorter = listviewColumnSorter;Handles...
Get AssociatedFileTypes (.txt = TextDocument)
/// /// Get File Type for given file./// /// Pass the path of file/// This method returns Associated file type like :-.pdf = Adobe Acrobat Document.txt = Text Documentprivate string GetAssociatedFileType(string filePath){ private const string STRING_SPACE = " "; string extension = string.Empty; if (!string.IsNullOrEmpty(filePath))...
File System Watcher in C#(Get notified after any modification)
Drag FileSystemWatcher control in your form from toolbox and add the events for created,deletion and renaming.Ex:-#region Designer viewthis.fileSystemWatcher.EnableRaisingEvents = true;this.fileSystemWatcher.IncludeSubdirectories = true;this.fileSystemWatcher.SynchronizingObject = this;this.fileSystemWatcher.Created += new System.IO.FileSystemEventHandler(this.fileSystemWatcher_Created);this.fileSystemWatcher.Deleted...