29 June 2013

What is the difference between char , varchar and nvarchar?

char(n)Fixed length non unicode character data with length of n bytes.n must be a value from 1 through 8,000.

varchar(n)variable length non unicode character data with length of n bytes.

nvarchar(n)variable length unicode character data of n characters. n must be a value from 1 through 4,000.

What are the properties of Sub-Query?

  • A subquery must be enclosed in the parenthesis.
  • A subquery must be put in the right hand of the comparison operator
  • A subquery cannot contain a ORDER-BY clause.
  • A query can contain more than one sub-queries.

ADO.NET Objects

  • Connection Object
  • DataReader Object
  • Command Object
  • DataSet Object
  • DataAdapter Object

Which namespaces are used for data access?

  • System.Data
  • System.Data.OleDB
  • System.Data.SQLClient

What are the data access namespaces in .NET?

    The most common data access namespaces :
  • System.Data
  • System.Data.OleDb
  • System.Data.SQLClient
  • System.Data.SQLTypes
  • System.Data.XML

What is the difference between public, static and void?

  • public :The keyword public is an access modifier that tells the C# compiler that the Main method is accessible by anyone.
  • static :The keyword static declares that the Main method is a global one and can be called without creating an instance of the class. The compiler stores the address of the method as the entry point and uses this information to begin execution before any objects are created.
  • void : The keyword void is a type modifier that states that the Main method does not return any value.

What are the types of comment in C#?

    There are 3 types of comments in C#.
  • Single line (//)
  • Multi (/* */)
  • Page/XML Comments (///).

Features of DataList

  1. Directional rendering
  2. Good for columns
  3. Item as cell
  4. Alternate item
  5. Updateable

Features of Repeater

  1. List format
  2. No default output
  3. More control
  4. More complexity
  5. Item as row
  6. Not updateable

Features of a GridView

  1. Displays data as a table
  2. Updateable
  3. Item as row
  4. Control over
  • Alternate item
  • Header
  • Footer
  • Colors, font, borders, etc.
  • Paging

What is the use of web.config? What is the difference between machine.config and web.config?

ASP.NET configuration files are XML-based text files for application-level settings and are saved with the name web.config. These files are present in multiple directories on an ASP.NET Web application server. Theweb.config file sets the configuration settings to the directory it is placed in and to all the virtual sub folders under it. The settings in sub directories can optionally override or change the settings specified in the base directory.

The difference between the web.config and machine.config files is given as follows:
  • <WinDir>\Microsoft.NET\Framework\<version>\config\machine.config provides default configuration settings for the entire machine. ASP.NET configures IIS to prohibit the browser directly from accessing the web.config files to make sure that their values cannot be public. Attempts to access those files cause ASP.NET to return the 403: Access Forbidden error.
  • ASP.NET uses these web.config configuration files at runtime to compute hierarchically a sole collection of settings for every URL target request. These settings compute only once and cached across further requests. ASP.NET automatically checks for changing file settings and do not validate the cache if any of the configuration changes made.

What are the various ways of authentication techniques in ASP.NET?

There are various techniques in ASP.NET to authenticate a user. You can use one of the following ways of authentication to select a built-in authentication provider:
  • Windows Authentication - This mode works as the default authentication technique. It can work with any form of Microsoft Internet Information Services (IIS) authentication, such as Basic, Integrated Windows authentication (NTLM/Kerberos), Digest, and certificates. The syntax of Windows authentication mode is given as follows: <authentication mode="windows" />
  • Forms Authentication - You can specify this mode as a default authentication mode by using the following code snippet: <authentication mode="Forms"/>
  • Passport - This mode works with Microsoft Passport authentication, as shown in the following code snippet: <authentication mode = "Passport"/>

27 June 2013

what is stored procedure in Sql server | what are the advantages of using stored procedures in sql server

stored procedure:
 
A stored procedure is a group of sql statements that has been created and stored in the database. Stored procedure will accept input parameters so that a single procedure can be used over the network by several clients using different input data. Stored procedure will reduce network traffic and increase the performance. If we modify stored procedure all the clients will get the updated stored procedure

Sample of creating Stored Procedure

USE AdventureWorks2008R2;
GO
CREATE PROCEDURE dbo.sp_who
AS
    SELECT FirstName, LastName FROM Person.Person;
GO
EXEC sp_who;
EXEC dbo.sp_who;
GO
DROP PROCEDURE dbo.sp_who;
GO

Advantages of using stored procedures

    a) Stored procedure allows modular programming. 

You can create the procedure once, store it in the database, and call it any number of times in your program. 

b    b) Stored Procedure allows faster execution. 

If the operation requires a large amount of SQL code is performed repetitively, stored procedures can be faster. They are parsed and optimized when they are first executed, and a compiled version of the stored procedure remains in memory cache for later use. This means the stored procedure does not need to be reparsed and reoptimized with each use resulting in much faster execution times. 

c    c) Stored Procedure can reduce network traffic. 

An operation requiring hundreds of lines of Transact-SQL code can be performed through a single statement that executes the code in a procedure, rather than by sending hundreds of lines of code over the network.

d    d) Stored procedures provide better security to your data

Users can be granted permission to execute a stored procedure even if they do not have permission to execute the procedure's statements directly.

In SQL we are having different types of stored procedures are there

a)    System Stored Procedures
b)    User Defined Stored procedures
c)    Extended Stored Procedures

System Stored Procedures:

System stored procedures are stored in the master database and these are starts with a sp_ prefix. These procedures can be used to perform variety of tasks to support sql server functions for external application calls in the system tables 

Ex: sp_helptext [StoredProcedure_Name]

User Defined Stored Procedures:

User Defined stored procedures are usually stored in a user database and are typically designed to complete the tasks in the user database. While coding these procedures don’t use sp_ prefix because if we use the sp_ prefix first it will check master database then it comes to user defined database

Extended Stored Procedures:

Extended stored procedures are the procedures that call functions from DLL files. Now a day’s extended stored procedures are depreciated for that reason it would be better to avoid using of Extended Stored procedures.

26 June 2013

BackUp the database with compression and without compression inseq server

compression

BACKUP DATABASE database_name

TO DISK = 'D:\database_name.BAK'

WITH COMPRESSION
 
Example:

BACKUP DATABASE exe

TO DISK = 'D:\exe.BAK'

WITH COMPRESSION
 
 
without compression

BACKUP DATABASE database_name

TO DISK = 'E:\database_name.BAK'

WITH NO_COMPRESSION, INIT

Example

BACKUP DATABASE exe

TO DISK = 'E:\exe.BAK'

WITH NO_COMPRESSION, INIT

Change the format of DateTime variable in asp.ner & c#

protected void btngetdate_Click(object sender, EventArgs e) 
{ 
DateTime dt = Calendar1.SelectedDate; 
string str = dt.ToString("dd:MM:yyyy"); 
txtDate.Text = str; 
}

Return value after INSERT in sql server

Use SCOPE_IDENTITY() to get the new ID value
INSERT INTO table (name) VALUES('bob');

SELECT SCOPE_IDENTITY()

23 June 2013

What is AJAX?


  1. AJAX is an acronym for Asynchronous JavaScript and XML.
  2. AJAX is a new technique for creating better, faster, and more interactive web applications.
  3. With AJAX, a JavaScript script can communicate directly with the server, with the XMLHttpRequest object. With this object, a JavaScript can exchange data with a web server, without reloading the page.
  4. AJAX uses asynchronous data transfer (HTTP requests) between the browser and the web server, allowing web pages to request small bits of information from the server instead of entire pages.
  5. The AJAX technique makes Internet applications smaller, faster and more user-friendly.

22 June 2013

Get List of table names in database


USE SampleDB

SELECT * FROM SYS.TABLES

Get List of Stored procedure names in database


USE SampleDB

SELECT * FROM SYS.PROCEDURES

Export Webpage to pdf using itextsharp dll

Asp.net code:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"
    EnableEventValidation="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <center>
        <div>
            <b>Export Webpage to pdf using itextsharp dll</b></div>
        <br />
        <div>
            <asp:GridView ID="gvDetails" AutoGenerateColumns="false" CellPadding="5" runat="server">
                <Columns>
                    <asp:BoundField HeaderText="UserId" DataField="UserId" />
                    <asp:BoundField HeaderText="UserName" DataField="UserName" />
                    <asp:BoundField HeaderText="Education" DataField="Education" />
                    <asp:BoundField HeaderText="Location" DataField="Location" />
                </Columns>
                <HeaderStyle BackColor="green" Font-Bold="true" ForeColor="White" />
            </asp:GridView>
        </div>
        <br />
        <asp:Button ID="btnPDF" runat="server" Text="Export to PDF" OnClick="btnPDF_Click" />
    </center>
    </form>
</body>
</html>

C# Code:

using System;
using System.Web;
using System.Web.UI;
using System.Data;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridview();
        }
    }
    protected void BindGridview()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("UserId", typeof(Int32));
        dt.Columns.Add("UserName", typeof(string));
        dt.Columns.Add("Education", typeof(string));
        dt.Columns.Add("Location", typeof(string));
        DataRow dtrow = dt.NewRow();    // Create New Row
        dtrow["UserId"] = 1;            //Bind Data to Columns
        dtrow["UserName"] = "Jc.adinarayana reddy";
        dtrow["Education"] = "B.Tech";
        dtrow["Location"] = "A.p";
        dt.Rows.Add(dtrow);
        dtrow = dt.NewRow();               // Create New Row
        dtrow["UserId"] = 2;               //Bind Data to Columns
        dtrow["UserName"] = "Ekanath";
        dtrow["Education"] = "McA";
        dtrow["Location"] = "A.p";
        dt.Rows.Add(dtrow);
        dtrow = dt.NewRow();              // Create New Row
        dtrow["UserId"] = 3;              //Bind Data to Columns
        dtrow["UserName"] = "Raja";
        dtrow["Education"] = "B.Tech";
        dtrow["Location"] = "A.p";
        dt.Rows.Add(dtrow);
        gvDetails.DataSource = dt;
        gvDetails.DataBind();
    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        /* Verifies that the control is rendered */
    }
    protected void btnPDF_Click(object sender, EventArgs e)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        this.Page.RenderControl(hw);
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0.0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }
}

OutPut: