Tuesday, May 31, 2011

.NET/ASP.NET interview Questions - Show us simple insert, update and delete operation using LINQ?

Answer:

Let us assume that we have the following table of Student with their respective fields.




First open visual studio > New > project > select ASP.NET empty web
application.

Add > New item > select Web Form and create a simple form like below.




Once you have done creating the form, now you have to add LINQ to SQL Classes in your project.
Add > New item > select LINQ to SQL Classes.
As soon as you click on add a new window will appear from that just click on server explorer expand the data connection and select your database then drag and drop the table on the .dbml file like below diagram.



Now you have to add a class library file in your project.
Add > New item > select Class.

usingSystem.Data.Linq;
usingSystem.Data.Linq.Mapping;

namespaceLinq_to_insert
{
 [Table(Name="Student")]
publicclassClass1
 {
privatestring _Name;
privatestring _Add;

publicstring Name
     {
get{ _Name = value;}                                               
get{return _Name;}
      }
publicstring Add
     {
set{ _Add = value; }
get{return _Add;}
     }
 }
}


Write code for insert update and delete with their respective buttons.
For adding record.

protectedvoidbtnAdd_Click(object sender, EventArgs e)
     {
DataClasses1DataContextObjDataContext = newDataClasses1DataContext();
StudentObjStud = newStudent();
ObjStud.StudentAdd = TextBox2.Text;
ObjStud.StudentName = TextBox1.Text.ToString();
ObjDataContext.GetTable().InsertOnSubmit(ObjStud);
ObjDataContext.SubmitChanges();
Response.Write("Record Successfully Inserted");

     }


For updating record.
protectedvoidbtnUpdate_Click(object sender, EventArgs e)
     {
DataClasses1DataContextObjDataContext = newDataClasses1DataContext();
StudentObjStud = newStudent();
string Name1 = TextBox1.Text;
string Address = TextBox2.Text;
var Update = ObjDataContext.Students.Single(p =>p.StudentName == Name1);
Update.StudentAdd = Address;
ObjDataContext.SubmitChanges();
Response.Write("Record Successfully Updated");

     }


For deleting record.
protectedvoidbtnDelete_Click(object sender, EventArgs e)
     {
DataClasses1DataContextObjDataContext = newDataClasses1DataContext();
StudentObjStud = newStudent();
string Name1 = TextBox1.Text.ToString();
var delete = ObjDataContext.Students.Single(s =>s.StudentName == Name1);
ObjDataContext.Students.DeleteOnSubmit(delete);
ObjDataContext.SubmitChanges();
Response.Write("Record Successfully deleted");


     }

You will be also interested in watching the below video, which are also asked in most of the interviews and favourable question of interviewers.




Please click here to see more .NET and ASP.NET interview questions
Regards,

Visit Authors blog for more .NET and ASP.NET interview Question


Monday, May 30, 2011

.NET and SQL Server interview questions - Can you describe Sql Server Views are updatable?

Answer:

View is a virtual table, which can contains data (rows with columns) from one or more table and you can retrieve data from a view.

Let’s demonstrate a simple example in which we will see that how to create a view on single table and will also see that if we update the view the respective table on which the view is created is updated or not.


Now let first see how to create view.

Go to View folder in SQL Server > Right click on it > select New View.





As soon as you click on New View, the following window will appear like below.




Now, just select the table name from the list on which you wish to create a View and Click on Add then click on close. Once you click on close a new window will appear which allow you to create View on the respective column.



After selecting the column name just save the view and give View a nice name.


Once you have completed the above step you will see that the respective View is added in the View folder.


Now let’s see that when we update the view the respective table is also updated or not.

Query:-

Update [Practice].[dbo].[Cust_View] set Customer_Contact = 96641122 where
Customer_Name = 'Feroz'
Now just go to the table on which the view was created and check whether the table is updated or not, you will see that the table is also updated when you update the View.
Now let’s create a view based on two tables and try to update a view.

create view View_Cust as SELECT    dbo.Customer.Customer_Name, dbo.Customer.
Customer_Contact,dbo.[Order].Product_Name,dbo.[Order].Price
FROM dbo.Customer
INNER JOIN dbo.[Order] ON dbo.Customer.Order_ID = dbo.[Order].Order_ID

Let’s try to Update View:


Query:-
Update [Practice].[dbo].[View_Cust] set Customer_Contact = 098767554,
Price = 4000 where Customer_Name = 'Feroz'

As you can see in the above query, I am trying to update a column from the Product table and another column from the Order table and try to execute the query the compiler will throw the below error.

Error Message:- View or function 'Practice.dbo.View_Cust' is not updatable because the modification affects multiple base tables.

This means that when you try to update both the table’s column from the view then it is not allowed but you can update single table column.

Please click here to see more .NET and SQL Server interview questions
Regards,

Visit Authors blog for more .NET and SQL Server interview Question


Sunday, May 29, 2011

.NET and SQL Server interview questions - Show SQL query in order to obtain names of employees with top 10 salaries?

Answer:

Let’s see a simple example to see, how exactly we can obtain entire employee
name who obtains top 10 salaries.

Assuming that we have following table for Employee.




Query:-

select Employee.EmpName,Employee.EmpSalary from Employee where Employee.EmpSalary in
(select distinct top(10)Employee.EmpSalary from Employee order by Employee.EmpSalary desc)

OUTPUT:-




You will be also interested in watching the below video, which are also
asked in most of the interviews and favourable question of interviewers.




Please click here to see more .NET and SQL Server interview questions

Regards,

Visit Authors blog for more .NET and SQL Server interview Question

Friday, May 27, 2011

ASP.NET/.NET interview Question - Encryption of connection strings in web.config file?

Answer:

When you host your site on server, sometimes happens that your site is handled by an third party or any other individual who is responsible to handle the server. As your site is handled or manage by another person it can be possible for that person to view your connection string and can make changes to the same. So in order avoid this we need to encrypt your connection string.

This can be achieved by using aspnet_regiis tool provided by the ASP.NET.

It’s a very simple 3 steps process.



Step 1:- Let first define the connection string in web.config file like below
code snippet.


<connectionStrings>

<add name="Constr" connectionString="Data Source=localhost;Initial
Catalog=YourDataBaseName; Integrated Security=True"/>

</connectionStrings>

In the above snippet code you can see that the connection string easily visible by anyone because it is in decrypted format. Hence to prevent or protect the connection string we need to encrypt connection string in such a way that it is not visible to anyone.


Step 2: - Just go to Visual Studio Command Prompt and use aspnet_regiis tool to encrypt the defined connection string like below diagram.



Now just execute the Visual Studio Command Prompt and if the encryption is done successfully a message will be displayed like below diagram.



Step 3:- Go to web.config file and you will see that connection string is now in encrypted format like below diagram.




You will be also interested in watching the below video, which are also asked in most of the interviews and favourable question of interviewers.


Please click here to see more ASP.NET and .NET interview questions
Regards,

Visit Authors blog for more ASP.NET/ .NET interview questions

Thursday, May 26, 2011

.NET and ASP.NET interview Question - Can you explain threading and show its practical implementation?

Threading is a parallel processing unit and helps you to access multiple tasks at a one moment of time. When we want to access parallel processing in our application we use Threading.
In order to use threading we first have to import System.Threading namespace in our application like below code. using System.Threading;
Below is the simple class in which I have defined two functions as Fun1 and Fun2.i have also created a DoTest function with an instance of thread as t1 and t2.finally I have invoked DoTest function in Main Method.
class Program 
{
public void Fun1()     
{
 for (int i = 0; i < 10; i++)        
{             
Console.WriteLine("i"+"="+i.ToString());             
Thread.Sleep(500);        
}      
}
public void Fun2()      
{
 for (int j = 0; j < 10; j++)          
{              
Console.WriteLine("j" + "=" +j.ToString());            
Thread.Sleep(500);     
}       
}
 static void Main(string[]args)      
{
  Program p = new Program();       
  p.DoTest();
  Console.ReadLine();      
}
 public void DoTest()      
{
 Thread t1 = new Thread(new ThreadStart(Fun1));    
 Thread t2 = new Thread(new
 ThreadStart(Fun2));
 t1.Start();
 t2.Start();      
}
}

Once you have completed the above steps just run your application and you will see the output like below diagram.
Output:



You can see that in the above diagram both the function Fun1 and Fun2 run at single moment of time with one after another and display their respective outputs.
You will be also interested in watching the below video, which are also asked in most of the interviews and favourable question of interviewers.




Please click here to see more .NET and ASP.NET interview questions

Regards,

Visit Authors blog for more .NET and ASP.Net interview questions

Wednesday, May 25, 2011

How to consume the service using WCF - Part 2

SQL and .NET interview Question - Why ADO.NET is better from ADO?

Answer:

The ADO.NET is better from ADO by the below reasons-




You will be also interested in watching the below video, which are also asked in most of the interviews and favorable question of interviewers.


Please click here to see more SQL/.NET interview questions

Regards,

Visit Authors blog for more .SQL/.NET interview questions

Tuesday, May 24, 2011

What is SOA, Services and Messages? - Part 1

How to create a simple model in ASP.NET MVC and display it in view? in H...

Understanding how to implement Model view Control pattern using J2EE and various Java frameworks


MVC stands for Model View Controller design pattern and is one of the widely used pattern especially in Web applications
The pattern segregates the presentation or UI layer as View layer, business logic or application processing into Controller layer and Model is the related data to be used for processing

Since it segregates each of the above three parts it becomes easy to replace one of the above component without affecting the other part and allows the application to replace the existing
component with advanced technology /tool/framework


You can watch my videos on MVC, Struts 2, Spring and other J2EE design patterns and frameworks




In this article we will see following topics

  • Implementing MVC using JSP/Servlet

  • Implementing MVC using Struts 2 framework

  • (Implementing MVC using Struts 2 framework will be part of next series

We will each of the above implementation in a “Hello name” example which takes name from the user and the displays a Hello name message

Integrated Development environment used is Eclipse Europa and Container used is Apache tomcat 6

Implementing MVC using JSP/Servlet

In case of MVC using JSP/Servlet following are the roles taken by each of the component involved





Step 1: Click New=>Other=>Web=>Dynamic web project



Step 2: Enter Project name as MVC and Click on Finish button



Step 3: Click on src and click on New=>package



Step 4: Enter name of package as com.questpond.controller




Similarly create one more package named com.questpond.model


Step 5: Right click Web Content folder New=>JSP


Enter the name of the jsp as index.jsp



Click on Finish button


Step 6: Enter the following code in index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Index jsp</title>
</head>
<body>
<form action="Action.do" method="get">
Enter name <input type="text" name="name"><br/>
<input type="submit" value="submit"/>
</form>
</body>
</html>

Step 7: Right click on com.questpond.model click on New=>Class. Name the class as ModelBean






Step 8: Within the ModelBean create a variable welcomeMsg and write setters and getters for same

String welcomeMsg;
public String getWelcomeMsg() {
return welcomeMsg;
}
public void setWelcomeMsg(String welcomeMsg) {
this.welcomeMsg = "Welcome "+welcomeMsg;
}


Step 9: Right click on com.questpond.controller and create New=>Servlet

Write the name of servlet as ActionServlet





Step 10: Write the following code within doGet method of ActionServlet

String name =request.getParameter("name");
ModelBean model = new ModelBean();
model.setWelcomeMsg(name);
request.setAttribute("welcomeMsg", model.getWelcomeMsg());
RequestDispatcher dispatch = request.getRequestDispatcher("welcome.jsp");
dispatch.forward(request, response);

Step 11: Create a JSP named welcome.jsp following Step 5 and put the following code inside jsp

<title>Welcome</title>
</head>
<body>
<%=request.getAttribute ("welcomeMsg").toString() %>
</body>

Step 12: Right click on the project and click on export option (Export=>WAR file)






Step 13: Point the destination to the webapps folder of tomcat and check all the options present


Click on finish button


Step 14: Start tomcat (Tomcat=>start.bat) and put the following URL in web browser
http://localhost:8080/MVC/


Following page will appear




Step 15: Enter any name for e.g. John and click on submit button

A page with welcome message will appear as follows






MVC using Struts 2:


Struts 2 makes use of Intercepting Filter pattern which makes use of Filters which can be used for pre processing before executing controller as well as post processing after controller
execution.

For doing pre processing as well as post processing Struts 2 uses Interceptors. Thus request in this case comes to interceptors which then invokes action and based on result of action execution
corresponding view will be displayed to user. This configuration of view with result returned by action is done in an xml known as struts.xml

Model in this case can be Java bean class which can be used with Action







In case of MVC using Struts 2 following are the roles taken by each of the component involved


Advantage of struts 2 MVC is that view for particular action is configured in xml (struts.xml or other xmls included within struts.xml) and hence there is no direct dependency between controller and view

Step 1: Click New=>Other=>Web=>Dynamic web project





Step 2: Enter Project name as WelcomeStruts2MVC and Click on Finish button



Step 3: Copy following jars from the struts 2 libraries from distribution to WEB-INF/lib folder

• commons-logging-1.0.4.jar

• freemarker-2.3.8.jar

• ognl-2.6.11.jar

• struts2-core-2.0.14.jar

• xwork-2.0.7.jar

Step 4: Make following filter entry in web.xml

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Note: In higher version of struts 2 we can use
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter for filter-class


Step 5: Create an XML within src folder and name it struts.xml




Step 6: Put the following lines inside struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default">
<action name="welcomeAction" class="com.questpond.action.WelcomeAction">
<result name="success">welcome.jsp</result>
</action>
</package>
</struts>



Step 7: Create a new package by using New=>package and give name as com.questpond.action





Step 8: Click on the package and create a new class by using

New => Class and name the class as WelcomeAction




Step 9: Write the following code within the above class

String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String execute(){
return Action.SUCCESS; }


Step 10: Create a new jsp by using New=>JSP and name it index.jsp and put the following code within the jsp

<%@ taglib prefix="s" uri="/struts-tags"%>
<s:form action="/welcomeAction.action">
<s:textfield name="name" label="Enter name"></s:textfield>
<s:submit></s:submit>
</s:form>


Step 11: Create one more jsp with name as welcome.jsp and put the following code

<%@ taglib prefix="s" uri="/struts-tags"%>
Welcome <s:property value="name"/>


Step 12: Export the project as war by using right clicking the project and clicking on Export option





Fill the details like destination (where the war has to be kept) in the window. Check all other options and Click on Finish button



Step 13: Start apache tomcat and put the following URL in web browser
http://localhost:8080/WelcomeStruts2MVC/


The following page will appear and fill the name with any string value




Step 14: After filling details click on submit button on which following page will be displayed




What’s next

In my next series we will see how to implement MVC using Spring framework

.NET and ASP.NET interview Question :- Elaborate different types of assemblies?

In .NET there are basically three different types of assemblies as follows.
1.Private assemblies:-A private assembly is normally used by a single application and is stored in the application's directory.
2.Public/shared assemblies:- A shared assembly is normally stored in the global assembly cache which is a repository of assemblies maintained by the .NET runtime.
3.satellite assemblies:-Satellite assemblies are often used to deploy language-specific resources for an application. These language-specific assemblies work in side-by-side execution because the application has a separate product ID for each language and installs satellite assemblies in a language-specific subdirectory for each language.
You will be also interested in watching the below video, which are also asked in most of the interviews and favorable question of interviewers.



Please click here to see more .NET/ Asp.Net interview questions

Regards,

Visit Authors blog for more .NET / Asp.Net interview questions

Saturday, May 21, 2011

What is SharePoint, WSS and MOSS?

How does WSS actually work?

C# and .NET interview questions - Describe about the various types of generic collections?

Answer:
There are basically four different types of generic collections which are as follows:-
1. List:-Lists are indexed based Generic Collections. Lists are Generic form of ArrayList.
List helps us to create flexible strong type collection as you can see in below code snippet i have defined List as "int" and "string".

//index based Generic collection          
List<int> ObjInt = new List<int>();       
ObjInt.Add(123);          
ObjInt.Add(456);          
Console.WriteLine(ObjInt[0]); //accessing the List by internal index based value.          
List<string> ObjString = new List<string>();          
ObjString.Add("feroz");

2. Dictionary:-Dictionary are key based generics collection.

Dictionary are generic form of Hashtable.

 //key based Generic collection          
Dictionary<int, int> ObjDict = new Dictionary<int,int>();          
ObjDict.Add(1,2);          
Dictionary<int, string> ObjDict1 = new Dictionary<int,string>();          
ObjDict1.Add(3, "feroz is a developer");          
ObjDict1.Add(4, "wasim is a developer");          
Console.WriteLine(ObjDict1[3]); //accessing the dictionary by defined key.

3. Stack:-Stack generic collection allows you to get value in "LIFO"(last in first out) manner.

// Stack           
Stack<string> ObjStack = new Stack<string>();          
ObjStack.Push("feroz");          
ObjStack.Push("moosa");          
Console.WriteLine(ObjStack.Pop());

4. Queue:-Queue generic collection allows you to get value in "FIFO"(first in first out) manner.

//Queue          
Queue<int> ObjStr = new Queue<int>();          
ObjStr.Enqueue(789);          
ObjStr.Enqueue(456);          
Console.WriteLine(ObjStr.Dequeue());



For more information about generic, please watch the below video.




Please click here to see more c# and Dotnet interview questions

Regards,

Visit Authors blog for more Most asked Dotnet interview questions


Friday, May 20, 2011

What is site and site collection?

What is the concept of ghosting and unghosting in SharePoint?

C# and .NET interview Question - Explain about the Generics?

Answer:

This is one of the most important typical question, which is asked in most of the interviews to check whether you know about generic.

Generic: Generic help us to create flexible strong type collection.


Generic basically seperate the logic from the datatype in order maintain better reusability, better maintainability etc.

Lets see an simple example to understand how exactly generic seperate logic from datatype.


In order to use Generic in your project you will first have to ensure that
you have imported "System.Collections.Generic" namespace.

    class Check<UNKNOWNDATATYPE>
  {
      public bool Compare(UNKNOWNDATATYPE i, UNKNOWNDATATYPE j)
      {
          if (i.Equals(j))
          {
              return true;
          }
          else
          {
              return false;
          }
      }
  }

In above code snippet, i have created a class called as "Check" with UNKNOWNDATATYPE so that, i can define different data types at run time. Now, in below code you can see that i have created two object of Check class with two different datatypes(int,string).

    class Program
  {
      static void Main(string[] args)
      {
          Check ObjCheck = new Check();    //here i have defined int datatype
          bool b1 = ObjCheck.Compare(1, 1);
          Check Obj1 = new Check();    //here i have defined string datatype
          bool b2 = Obj1.Compare("feroz", "kalim");
          Console.WriteLine("Numeric Comparison Result:" + b1);
          Console.WriteLine("String Comparison Result:"+ b2);
          Console.ReadLine();
      }
  }

Below is the full code snippet for the same so that you can try it by
yourself and see the resultant output.

    class Program
  {
      static void Main(string[] args)
      {
          Check ObjCheck = new Check();
          bool b1 = ObjCheck.Compare(1, 1);
          Check Obj1 = new Check();
          bool b2 = Obj1.Compare("feroz", "kalim");
          Console.WriteLine("Numeric Comparison Result:" + b1);
          Console.WriteLine("String Comparison Result:"+ b2);
          Console.ReadLine();
      }
  }

  class Check<UNKNOWNDATATYPE>
  {
      public bool Compare(UNKNOWNDATATYPE i, UNKNOWNDATATYPE j)
      {
          if (i.Equals(j))
          {
              return true;
          }
          else
          {
              return false;
          }
      }
  }

For more information about generic, please watch the below video.






Please click here to see more c# and Dotnet interview questions

Regards,

Visit Authors blog for more Most asked Dotnet interview questions

How can we create site in SharePoint?

Wednesday, May 18, 2011

How can we customize a SharePoint site?

What kind of readymade functional modules exists for collaboration?

C# and .NET interview Question - Explain what is Special Collections?

Answer:

Special Collection:-Special Collection are nothing but tailored .net
collection meant for specific purpose.

There are many types of special collection in .net but let only talk about
four important special collection which are mostly used.

The following are the four important special collections

1. CollectionsUtil:-
It help us to Create collections that ignores the
case in String.


Example:-
Hashtable ObjHash = CollectionsUtil.CreateCaseInsensitiveHashtable();
ObjHash.Add("feroz","he is a developer");
string str = (string) ObjHash["FEROZ"];
MessageBox.Show(str);

2. ListCollection:-Good for Collections that typically contain less
number of elements.


Example:-
ListDictionary ObjDic = new ListDictionary();
ObjDic.Add("feroz", "he is a developer");
ObjDic.Add("moosa", "he is a developer");

3. HybridCollection:- It is combination of ListDictionary and
HashTable.When the collection items are less then it will act as
ListDictionary and when number of items increases above 10 or above certain
number then it will act as a Hashtable Collection.


Example:-
 HybridDictionary ObjHybrid = new HybridDictionary();
ObjHybrid.Add("feroz", "he is a developer");
ObjDic.Add("Wasim", "he is a network administrator");
ObjDic.Add("moosa", "he is a hardware engineer");

4. StringCollection:- It is a very special Collection, which is
designed for storing only string items.





Also have a look on this video, which is asked in most of the interviews.




Please click here to see more c# and Dotnet interview questions

Regards,

Visit Authors blog for more Most asked c# interview questions

Tuesday, May 17, 2011

How can you display simple custom page in SharePoint?

Introduction to Enterprise Application Blocks

C# and .NET interview Question - Have you used crystal report in your project? If yes, then how?

Answer:
Any project you take in .NET or any language reporting is an integral part of the application. You will rarely find application without reports. Due to heavy usage of reporting in application this topic becomes a hot favorite of interviewers. There are two prominent technologies by which you create reports in .NET one is crystal reports and the other is SQL reporting services. In this question we will try to answer from the crystal report point of view.

So again a very typical .Net interview question which is asked to understand if you know how to create crystal report.

Let’s demonstrate a simple example to see that, how we can create crystal report
in our project.



Creation of crystal reports its basically 7 step process as following.

Step 1:-This is very simple and basic step for adding crystal report in the
project for that just click on the "Project" menu and select "Add New Item" -->
"Reporting"--> "Crystal Report".












Step 2:-When you click on add button the following window will appear and you
can select your choices according to your project requirement and then click OK.






Step 3:-As soon as you click on OK button a new window will appear from that
expand Create New Connection ->OLEDB(ADO) as you can see in below diagram.






Step 4:-Now, Expand the OLEDB(ADO) folder and a new window will appear with all
the connection providers from that you can select your own connection provider
name and click on “Next”.






Step 5:-When you click on Next a new window will pop-up where you can define
your server name and your database name then click on Next another window will
pop-up then click on “Finish” later you can see a new window like below diagram
with your selected database then you can select the table on which you want to
generate report and click on “Next”.






Step 6:-Choose the field name, which you want to display on your report and
click on “Finish”.







Step 7:-Once you have completed the above step then create a new form and place
a CrystalReportViewer from the toolbox and define the report source like below
diagram.







Once you select the report source click on “OK”, now you can run your project
and see the report.




Please click here to see more c# and Dotnet interview questions

Regards,

Visit Authors blog for more Most asked c# interview questions