Monday, August 26, 2013

Create Connection String in Asp.net using web.config file

Hello Friends,

Today I am writing this post because of I found out that beginners got a problem to create connection with database in web config file in asp.net. So, Solution is here. Enjoy it.....

Web Config File

<configuration>

  <connectionStrings>

    <add name="nameofConnection" connectionString="Data Source=servername; Initial Catalog=DatabaseName; User ID=UserName; Password=Password;"/>

  </connectionStrings>

  <system.web>
    <compilation debug="false" targetFramework="4.0" />
  </system.web>

</configuration>


Default.aspx

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

<!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 runat="server">
    <title>Connection String Demo</title>
</head>

<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView runat="server" ID="GridView1">
        </asp:GridView>
    </div>
    </form>
</body>
</html>



Default.aspx.cs

Add System.Configuration and System.Data.SqlClient namespace to add connection with sql.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)

   {

string connectionString = ConfigurationManager.ConnectionStrings["nameofConnection"].ConnectionString;

string query = "SELECT ProductID, ProductName, UnitPrice FROM tblProduct";
       
SqlDataAdapter da = new SqlDataAdapter(query, connectionString);

DataTable table = new DataTable();

da.Fill(table);

GridView1.DataSource = table;

GridView1.DataBind();

   }
}

If you like this post share it.. If you encounter any problems, feel free and comment below to find solution. Share Your Experience with us.










Sunday, August 25, 2013

Creating a virtual directory in IIS 7.5 and 7.0

Hello Friends,

Many times we face the problem to host our website on local
machine to createa virtual directory, So solutions is here for creating virtual directory in IIS 7.5 and 7.0.

Since IIS 7, there exists a separate concept for a virtual directory and an application.
You can map a virtual directory to a physical directory that is located on a local  a or remote computer. The physical directory (under the specified name of the virtual directory) then becomes part of the application's URL.
An application, on the other hand, is a group of files that provides services over protocols. So if you want to run your website as http://localhost/Demo, you have to use an application instead of a virtual directory and specify Demo as the application's alias.

To create a virtual directory:
Open IIS Manager
On Windows 7: Open Start -> Control Panel -> System and Security category ->
                        Administrative Tools -> Internet Information Services (IIS) Manager.


         On Windows Server 2008 or Windows Vista: Open 
Start -> Control Panel ->
              System and Maintenance category -> Administrative Tools ->
                                      Internet Information Services (IIS) Manager.
Expand local computer -> Sites -> right-click on Default Web Site (or other website if you're running multiple websites on the same computer) and choose Add Virtual Directory... 

An Add Virtual Directory dialog appears.
Enter the Virtual Directory Alias. If you want the website to run as http://localhost/KenticoCMSDemo, enter alias KenticoCMSDemo.
Type a path or browse to the physical directory that contains the chosen directory.


5. Click 
OK.
The system creates a new virtual directory.
Right-click the virtual directory and choose Convert to Application.
An Add Application dialog appears.
7.Click Select... and choose the ASP.NET v4.0 application pool from the drop-down menu.

8. Click OK.
The system converts the virtual directory to an application.
Alternatively, you can create an application in one step by right-clicking a web site and choosing Add Application... and filling the required information in the Add Application dialog as mentioned above.
Configuring application pools in IIS 7 and IIS 7.5
Application Pools provide you with additional level of website management. They are supported only by Windows Server 2003/2008/Vista/7. You can configure them in the Internet Information Services (IIS) Manager under local computer -> Application Pools.


  
You can check and change the assigned application pool by right-clicking an application under local computer -> Sites -> Default Web Site (or other web site) and selecting Manage Application -> Advanced Settings...

  
You can set the Recycling and other options by right-clicking on an application pool under local computer -> Application Pools and selecting Advanced Settings....

  

If you like this post share it.. If you encounter any problems, feel free and comment
 below to find solution. Share Your Experience with us.



Friday, August 23, 2013

Object Oriented Programming (Oops) Concepts


Hello Friends,

Today I am writing this post because of this is very important question in interview . And Before starting programming you should be about the concepts of Oops.




What is OOP? 
The object oriented programming is commonly known as OOP. Most of the languages are developed using OOP concept. Object-oriented programming (OOP) is a programming concept that uses "objects" to develop a system.
A programming object has an ability to perform actions and has attributes. It performs just like real world entities for e.g. a motor bike. A bike performs actions such as ’Start’, ’Stop’ etc., and it has attributes like red color, 150 cc etc. So does an Object. Actions and attributes are represented by Methods and fields or properties respectively in programming language.
An object hides the implementation details and exposes only the functionalities and parameters it requires to its client. Here also an object shares the same concept as that of a bike. While driving a motor bike, we are unaware of its implementation details such as how it is developed, internal working of gears etc.? We know only the functions or actions it can perform.

What are the various elements of OOP? 
Various elements of OOP are:
• Object
• Class
• Method
• Encapsulation
• Information Hiding
• Inheritance
• Polymorphism

Explain an object. 
An object is an entity that keeps together state and behaviors. For instance, a car encapsulates state such as red color, 900 cc etc and behaviors as ’Start’, ’Stop’ etc., so does an object.
An object is an instance of a class. If you consider Dog as a class, it will contain all possible dog traits, while object German Shepherd contains characteristics of specific type of dog.


Define a class. 
A class represents description of objects that share same attributes and actions. It defines the characteristics of the objects such as attributes and actions or behaviors. It is the blue print that describes objects. 

What is Method?  

Method is an objects behavior. If you consider Dog as an object then its behaviors are bark, walk, run etc.

Explain Encapsulation concept in OOP. 
Encapsulation means keeping actions and attributes together under a single unit.
This can also be understood using a motor bike example. A bike has actions such as ‘switch on light’, ’horn’ etc. and attributes such specific color, size, weight etc. Here

the actions and attributes are bundled together under a single unit, bike.
In a programming language, methods and properties that correspond to actions and attributes respectively are kept under a unit called object. The advantage of encapsulation is that the implementation is not accessible to the client. The user has to know only the functionality of encapsulated unit and information to be supplied to get the result.

What is Information Hiding in OOP? 
Information hiding concept restricts direct exposure of data. Data is accessed indirectly using safe mechanism, methods in case of programming object. Taking bike as an example, we have no access to the piston directly, we can use ’start button’ to run the piston. You can understand the advantage of information hiding concept from this example. If a bike manufacturer allows direct access to piston, it would be very difficult to control actions on the piston.

Define Inheritance. 
Inheritance concept in OOP allows us to create a new class using an existing one. It also allows the new class to add its own functionality. This concept can also be related to real world entity. A bike manufacturer uses same mechanism of existing version of the bike while launching a new version with some added functionalities.

This allows him to save time and efforts.

Explain the term Polymorphism. 
Polymorphism means the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends on the data types used in the operation.

  
What is Overloading Polymorphism? 
Overloading allows multiple functions to exist with same name but different
parameters. Again if you take bike as an example, it has a function Start with two forms i.e. ’Auto Start’ and ’kick start’.

Explain Overriding Polymorphism. 
Overriding means changing behavior of methods of base class in derive class by overriding the base class methods. If class A is a base class with method ’calculate’ and class B inherits class A, thus derives method ’calculate’ of class A. The behavior of ’calculate’ in class B can be changed by overriding it.

What are the advantages of OOP? 

Following are the advantages of OOP: 

• It presents a simple, clear and easy to maintain structure.
• It enhances program modularity since each object exists independently.
• New features can be easily added without disturbing the existing one.
• Objects can be reused in other program.

If you like this post share it.. If you encounter any problems, feel free and comment below to find solution. Share Your Experience with us.


  


  


Thursday, August 22, 2013

Debug Editor Shortcut Keys in Visual Studio

Hello Friends,

Today I am writing this post because of debugging is very critical part of developing and using debugging best shortcut we can do debug faster and smoother, So lets use it next time in your project.

Use the following key combinations while you are debugging your project.

Note:  You can change or create keyboard shortcuts in Keyboard of the Environment options in the Options dialog box.

1.             Display documentation for the active window .... F1
2.            Display a system menu for the application window...ALT+SPACEBAR
3.            Add and remove breakpoints on the current lines... F9
4.           Clear all breakpoints................... CTRL+SHIFT+F9
5.            Disable breakpoint....................... CTRL+F9
6.           Display Auto window and move cursor into it..... CTRL+ALT+A
7.            Display Breakpoints dialog box............ CTRL+B
8.             Display Call Stack window and move cursor into it... CTRL+ALT+C
9.            Display Immediate window and move cursor into it.
10.       Not available if you are in the Text Editor window....... CTRL+ALT+I
11.       Display Locals window and move cursor into it............ CTRL+ALT+L
12.      Display Running Document window and move cursor into it.. CTRL+ALT+R
13.       Adds a watch on the currently selected word.............. SHIFT+F9
14.       Display the next statement.............. ALT+* on the NUM pad
15.       Display the shortcut menu................ SHIFT+F10
16.      Display Threads window and move cursor into it........... CTRL+ALT+H
17.      Display Watch window and move cursor into it..CTRL+ALT+W
18.      End debugging session.................................... SHIFT+F5
19.      Execute code one statement at a time, following
        execution into function calls Step Into)................. F11
20.       Execute the next line of code but not follow
        execution through any function calls (Step Over)......... F10
21.       Execute the remaining lines of a function in
        which the current execution point lies (Step Out)........ SHIFT+F11
22.       Restart a debugging session.............................. CTRL+SHIFT+F5
23.       Resume execution of your code from the current
24.       statement to the selected statement (Run to Cursor)..... CTRL+F10
25.       Run the application..................................... F5
26.       Run the code without invoking the debugger
   (Start without Debugging)............................... CTRL+F5
   Set the next statement.................................. CTRL+SHIFT+F10
   Stop execution (Break).................................. CTRL+BREAK


If you like this post share it.. If you encounter any problems, feel free and comment below to find solution. Share Your Experience with us.