April 24, 2013

Copy and Clone method


DataTable.Copy()  Vs DataTable.Clone()



Both the Copy and the Clone methods create a new DataTable with the same structure as the original DataTable. 

The new DataTable created by the Copy method has the same set of DataRows as the original table

whereas the new DataTable created by the Clone method does not contain any DataRows."


DataTable.Copy()
DataTable.Clone()
Create a new methods with same structure
Create a new methods with same structure
Data Row / Data in table is also copied
Data in table is not copied

JIT : Just intime Compiler


Different Types of JIT Compilers

JIT compiler is a part of the runtime execution environment.

In Microsoft .NET there are three types of JIT compilers:

        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.

However, these compiled methods are removed when they are not
required.

        Normal-JIT: -

                      Normal-JIT compiles only those methods that are called at runtime.

These methods are compiled the first time they are called, and then they are stored in cache. When the same methods are called again, the compiled code from cache is used for execution.

April 23, 2013

Access Specifier in C#


Access Specifiers in C#

  • Public
                    Accessible everywhere, public access

  • Private                Only within a class it is declared.

  • Internal                Only class within same assembly

  • Protected                Class and derived class

  • Protected Internal                Class and derived class within same assembly.


type
Default access specifer
Enum
public


Class
private


Stuct
private


interface
public



Insert data into Identity Column


Query to insert data into identity column



SET IDENTITY_INSERT  [TABLENAME] ON 


INSERT INTO [TABLENAME]
(IDENTITYCOLUMN, COLUMN1, COLUMN2 ,COLUMN3)
VALUES 
(1, 'COLUMN VALUE1' , 'COLUMN VALUE2' , 'COLUMN VALUE3'   )


SET IDENTITY_INSERT  [TABLENAME] OFF

April 22, 2013

Run SQL server job using query


To start a job

In Object Explorer, connect to an instance of Database Engine.

On the Standard bar, click New Query.

Copy and paste the following example into the query window and click Execute.

-- starts a job named Weekly Sales Data Backup. 

USE msdb ;

GO

EXEC dbo.sp_start_job N'YOURJOBNAME' ;

GO



April 16, 2013

Dynamic Port No of Asp.net Website




  1. First select website, and press F4 i.e Properites of website, you will find some properties
  2. Here one property Use Dynamic port : set to False




April 11, 2013

User Controls


A user control is a kind of composite control that works much like an ASP.NET Web page—you can add existing Web server controls and markup to a user control, and define properties and methods for the control. You can then embed them in ASP.NET Web pages, where they act as a unit.

To include a user control in a Web Forms page

In the containing ASP.NET Web page, create an @ Register directive that includes:

TagPrefix attribute, which associates a prefix with the user control. This prefix will be included in opening tag of the user control element.

TagName attribute, which associates a name with the user control. This name will be included in the opening tag of the user control element.

Src attribute, which defines the virtual path to the user control file that you are including.

In User control page:-     File name = WebUserControl.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs"
    Inherits="WebUserControl" %>
<asp:TextBox ID="txtDateControl" runat="server"></asp:TextBox><asp:Calendar ID="dtpicker"
    runat="server"></asp:Calendar>


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="DemoWebUserControl.ascx.cs" Inherits="DemoWebUserControl" %>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" />


In my web form we need to register user control.

<%@ Register TagPrefix="Uc1"  TagName="UserControl" Src="~/DemoWebUserControl.ascx"  %>


Added user control in my page

        <Uc1:UserControl   ID="ddl1" runat="server" />




        <asp:Button ID="btnSubmit" runat="server" Text="Submit"
            onclick="btnSubmit_Click" />

Now if we want to access the textbox and calendar control in my code behind file, we use following code.

    protected void btnSubmit_Click(object sender, EventArgs e)
    {

        

        DropDownList  ddl1 = (DropDownList)dtpicker.FindControl("ddl1");
       
        txt.Text = ddl1.SelectedValue.ToString();

        spMsg.InnerText = txt.Text;

    }


In above code to get control values of Calendar and Textbox we need to FindControl method.
Then we can easily access values of these controls.

April 7, 2013

Validation Controls in Asp.Net


ASP.NET validation controls validate data first on the client and then on the web server. If a client disables JavaScript on the browser then, client side validations are bypassed and validations are performed on the web server.

Validation controls also automatically provide server-side validation. Server-side validation is always performed, whether or not client-side validation has occurred. This double-checking ensures that custom validations are performed correctly and that client-side validation has not been circumvented.

Validation Controls in Asp.Net
  • RequiredfieldValidator
  • CompareValidator
  • CustomValidator
  • RegularExpressionValidator
  • ValidationSummary
  • RangeValidator


RequiredfieldValidator:
                Checks whether a control contains data

 CompareValidator:
Checks whether an entered item matches an entry in another control

RangeValidator:
Checks whether an entered item is between two values

RegularExpressionValidator:
Checks whether an entered item matches a specified format

CustomValidator:
Checks the validity of an entered item using a client-side script or a server-side code, or both
ValidationSummary:

Displays validation errors in a central location or display a general validation error description