Search This Blog

Tuesday, October 22, 2013

Boxing and Unboxing C#


Boxing is the process of converting a value type to the type object. When the CLR boxes a value type, it wraps the value inside a System.Object and stores it on the managed heap.
Unboxing extracts the value type from the object.

Example:

int i = 10;
object o = i; // boxes i
i = (int)o;   // unboxing





SQL Statements - DML, DDL,DCL

SQL Server > SQL Statements

SQL Statements are used for querying with database

Data Manipulation Language (DML)

Data Definition Language (DDL)

Data Control Language (DCL)
  • Grants or remove rights to database and structures within it






Monday, October 21, 2013

Run exe from SQL Server

SQL ServerSystem Stored Procedures > xp_cmdshell

xp_cmdshell is an extended stored procedure provided by Microsoft and stored in the master database.
This procedure allows you to issue operating system commands directly to the Windows command shell via T-SQL code.

Example: How to run executable from SQL Server?

exec master.dbo.xp_cmdshell 'mkdir "c:\MyDir\"'









Thursday, October 17, 2013

Class and object C#

C# > OOP > Class and object


A class is an abstraction of the characteristics and behavior of an object type. Classes can inherit from one other class, but can implement multiple interfaces.
A class is a template for defining objects.
A class should not be confused with an object.
An object is an instance of a class.




Difference between class and object

Class is like a template or blueprint of the object and resides on hard disk.
Object is real world implementation of a class and resides on RAM.

Example:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public class Person // define Person class
    {
        public string Name { get; set; } // Name property
    }

    public partial class Form1 : Form
    {
        private void Form1_Load(object sender, EventArgs e)
        {
            Person p1 = new Person(); // create new Person object
            p1.Name = "Dan";
        }
        public Form1()
        {
            InitializeComponent();
        }
     }
}

 





Wednesday, October 16, 2013

Determine control ToolStripItem was clicked on

C# > Controls > ContextMenuStrip


Scenario:
We have many labels on forms and one ContextMenuStrip. How can we find the control which was clicked?

Solution:

private void copyToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ToolStripItem menuItem = sender as ToolStripItem;
            if (menuItem != null)
            {
                ContextMenuStrip owner = menuItem.Owner as ContextMenuStrip;
                if (owner != null)
                {
                    Control sourceControl = owner.SourceControl;
                    Label lbl = sourceControl as Label;
                }
            }
        }





Monday, October 14, 2013

Print preview dialog full screen C#

C# > PrintPreviewDialog > Full Screen



PrintPreviewDialog dlg = new PrintPreviewDialog();
((Form)dlg).WindowState = FormWindowState.Maximized;
dlg.ShowDialog();





Center DIV

CSS margin property sets all the margin properties (top, right, bottom, left).

<div style="border: thin solid #C0C0C0; width: 800px;margin:0 auto;">
        centered content
</div>