Friday, July 13, 2012

Dot Net Interview questions for 2+ years experience

Hi All,

If you have 2+ years of experience then you should be ready for more paper work instead of oral in interview because there you have to prove yourself in-front of interviewer.

I have collected some interview questions those have attended by me and my friends.

In this article, I am giving you some Dot Net Interview questions for 2+ experiences.


1. Tell about your technical profile.
2. What was your role in your project?
3. In which module you have worked explain?
4. Describe GridView events (Paper).
5. How to change Label's color based on Label's value  (Paper)?
6. Write the code to perform edit and delete operations using  GridView (Paper).
7. What are the Validation controls in ASP.Net?
8. How you will implement Custom Validator Control functionality (Paper)?
9. What are Generics?
10. What is the  difference between HashTable and Dictionary?
11. What is Ajax and  Jquery?
12. Which control have you used in AJAX?
13. What is the use of ModalPopUpExtender (Paper)?
14. WCF Basics (Types of binding)
15. What are Database Constraints?
16. Difference between Primary and Unique key?
17. Difference between Function and Procedure?
18. Can we store DataSet in View State?
19. When we will store DataSet in Session then which memory will be filled client side or server side?
20. Difference between reference and out parameter?
21. How to execute stored procedure?


1. What is View State?
2. Where is View State is saved and how View State value is retained between Post Back. (Practical)?
3. Form Authentication Process (Using Web.Config file and Database in paper).
4. If View State value is "X" and I have changed it to "Y" in Page_Load then what will be the final value of View State?
5. Page Life cycle with use.
6. Performance Analyzer tool.
7. How to declare unique key?
8. Diff. between Equi join and Right outer join (Paper)?
9. Define Caching types.
10. How to implement SQL Cache (Paper)?
11. How to call Web service using AJAX (Paper)?
12. How to change Color of Label using Jquery (Paper)?
13. What is Table Object/Variable?
14. How to call stored procedure using Entity Framework?
15. What is the difference between Overloading and Overriding?
16. What is the difference between ExecuteScalar() and ExecuteNonQuery()?
17. What if I will pass Select * in ExecuteScalar()?


1. Tell me about projects.
2. Your role in project.
3. Which performance tool you have used?
4. Define abstract class and interface?
5. Why to use static members?
6. What is partial class and advantages?
7. GridView and DataList differences.
8. State Management type.
9. What is view state and use?
10. Caching techniques.
11. WCF and Web service differences.
12. Define WCF contracts.
13. Define design pattern.
14. What is facade pattern?
15. Triggers use and types.
16. Define cursor.
17. Difference between clustered and non-clustered index.
18. How many clustered index can be declared for a table.
19. What is view?
20. What is AJAX and Update-panel?
21. If you have 2 Update-panel then how to update one update panel from second?


1. Define your Technical skills.
2. Your Role in project.
3. Define features of OOPS.
4. How you will replace the functionality of parent class function in child class.(Paper)
5. Difference between Interface and abstract class (Use).
6. Functions of CLR.
7. Where you will use Cookie, Session and View State.
8. What are InProc and OutProc Session?
9. If you will save session in OutProc then where it will be saved and when it will be expired.
10. Difference between Web service and WCF
11. Design pattern.
12. Write sequence of select query-

 [ WITH ]
SELECT select_list [ INTO new_table ]
 [ FROM table_source ]
 [ WHERE search_condition ]
[ GROUP BY group_by_expression ]
[ HAVING search_condition ]
[ ORDER BY order_expression [ ASC | DESC ] ]

The UNION, EXCEPT and INTERSECT operators can be used between queries
to combine or compare their results into one result set.

13. What is ROW_NUMBER () in SQL Server?
14.  Difference between Union and Join.
15. Return value for ExecuteNonQuery().
16. Can we execute DML command in ExecuteScalar()?
17. Difference between DataSet and DataReader.
18. If provider is given OracleClient then can we connect with SQL Server?
19. Where you have used JQuery in your project?
20. Namespace for web-part (SharePoint)    - System.Web.UI.WebControls.WebParts Namespace
21. For creating a site what are the main concepts you need to consider in UL layer, middle-ware and Database Layer.


1. Explain different versions of .Net Framework.
2. What is OPPS and explain concept of OPPs?
3. What is static members and where you have used static members in your project?
4. What is difference between Constant  and ReadOnly?
5. Explain different Access Specifier.
6. What is Entity Framework? Explain difference between LINQ and Entity Framework.
7. Explain Page life cycle.
8. Explain Membership provider.
9. What is WCF?
10. Explain different types of WCF Binding and where you will use which binding?
11. Explain Index in SQL Server. Have you created any index for your project?
12. What is difference between Primary key  and Unique key?
13. What is Stored procedure and it's advantages?


1. What is difference between ArrayList and HastTable?
2. Where we have to use static members?
3. What is constants?
4. What is difference between Interface and Abstract class?
5. How you will handle error in C#?
6. What is the use of Virtual?
7. What is App Domain?
8. What is Session and Cache object?
9. What is Worker Process?
10. Write syntax for stored procedure.
11. How to handle error in Stored Procedure?
12. Explain Binding in WCF.
13. Explain Contract in WCF.
14. How you will host WCF service?
15. How to handle Error in WCF service?

1. Explain your Projects
2. What is Generics?
3. What is Delegate and Events?
4. What is difference between Protected and Protected Internal?
5. What is Entity Framework?
6. Explain Page Life Cycle.
7. Explain Session and Application object.
8. What is Worker Process?
9. What is ISAPI?
10. Use of Global.asax?
11. What us JQuery and How you will use JQuery in your application?
12. What is ISNAN?
13. Have you used Telerik controls in your Project?
14. What is stored procedure?
15. How to call Stored Procedure using .Net code?
16. What is Delete and Truncate?
17. How you will insert Bulk records in database?


These are the questions those have attended by me and my friends in different companies; here we can see that most of the questions are same. I hope these questions will help you all to attend the interviews.


Thursday, July 12, 2012

How to generate random color in C#?

In some of the case, we have a requirement to generate Random color for controls, this can be done by using Random class, Random class allows us to generate random number from given range, as we know that we can generate color using number combination, like (256,256,256).

Color is generated using combination of (256,256,256) numbers, these numbers represent RGB colors means RED, GREEN, BLUE colors. Every color is combination of RED, GREEN, BLUE colors only. So to generate random color we have to generate random combination of these numbers (256,256,256).

 Here I am explaining - How to generate random color in C#?
In this example, I have used Color.FromArgb() method, which accepts these parameters for color combination. This method returns generated color using given parameters, but we have to generate random color so we have to pass random color combination.

Here is code-

   private void button1_Click(object sender, EventArgs e)
            //Generating object for Random class 
            Random objRand = new Random();
            //Generating object for Color class
             Color objColor = Color.FromArgb(objRand .Next(256),objRand .Next(256),objRand .Next(256));

            //Assigning newly generated color to Button1 

            button1.ForeColor = objColor ; 

In this code, first I have defined object of Random class, which will help us to generate random number.  After that using Color class object I am generating color combination-

   Color objColor = Color.FromArgb(objRand .Next(256),objRand .Next(256),objRand .Next(256));

This line of code will return color which will be in format of color call object so we need any color class object to hold this color. Here I have declared one object by named objColor which is representing color class object. 

Finally I am assigning generated color to Button1.

   button1.ForeColor = objColor ;

Here objColor is object of color class which holds generated random color using  Color.FromArgb() function.


Wednesday, July 11, 2012

How to get nth record form table?

If we are filling result to any data-source then it is easy to get nth record from that data-source, by passing row index we can access nth record, but for this we have to perform two steps.

1. First we have to fill data source
2. Based on row index we have to get data from data-source.

Instead of these steps, we can do this directly in database side only, for this we have to use ROW_NUMBER () in query. This function include one sequence number for each record in result set. For this first we have to include ORDER BY clause in query because based on that only ROW_NUMBER() function include one sequential number for record. 


select *
from (select ROW_NUMBER()  over (order by columnname) as rownum from tablename) t1
where t1.rownum =index

Here index is nth row; we have to replace with any number.

Here is example-
Select *
from (select ROW_NUMBER()  over (order by columnname) as rownum from tablename) t1
where t1.rownum =2

This query will return 2nd row from table. Result set contains sequence number based on ORDER BY clause which has performed over given column. Sequence number can be different if we are passing different column name for ordering. We can also put where condition in inner query.


Tuesday, July 3, 2012

How to get Identity column value after inserting record using DataAdapter?


DataAdapter is an object which provides facility to interact with database. Using this object we can fill any DataSet class object or we can perform some command over database. Generally it is used for filling DataSet with database result but it can also be used for inserting record to database.

After inserting record, suppose if we want to get identity column value of new record then again we have to query to database. This process degrade the application performance because for this we have to make two trips of database which should not be happen. This task cab be done using one database trip only.  In this article, I am explaining - How to get Identity column value after inserting record using DataAdapter?

Here is code-        

            SqlConnection con = new SqlConnection("Connection string");
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("select * from TableName", con);
            //Assigning schema of Table to DataSet
            da.FillSchema(ds, System.Data.SchemaType.Source, "TableName");
            da.Fill(ds, "TableName");

            //Creating object of CommandBuilder to perform insert operation over DataSet
            SqlCommandBuilder cmdb = new SqlCommandBuilder(da);
            //Adding new row to DataSet
            DataRow row = ds.Tables[0].NewRow();
            //Filling data to row
            row["col1"] = "value1";
            row["col2"] = "value2";

            //Adding newly created row to DataSet object

            //Updating changes to DataSet
            da.Update(ds, "TableName");

            //Getting identity column value of newly added record
            int identityValue = Convert.ToInt32 ( row["identityColunmName"]);

In above code, I am inserting new record to database using DataAdapter, I have used one DataAdapter class object - "da”. First, I am getting record into DataSet object - "ds", but for getting identity column value we need to assign table schema to DataSet object before filling.

Like this-

           //Assigning schema of Table to DataSet
            da.FillSchema(ds, System.Data.SchemaType.Source, "TableName");
            da.Fill(ds, "TableName");

After execution of these lines table schema will be assigned to DataSet object with identity column, so that while adding new row to DataSet we can access identity column value.

Like this-

           //Getting identity column value of newly added record
            int identityValue = Convert.ToInt32 (row["identityColunmName"]);

Here "identityColunmName" is name of identity column in the table, once we will add new row to DataSet object we can access identity column value of newly added record.


In this example it is must that database table should contain identity column otherwise this example will not work. Next value for column can be accessed only when that column is identity column.


Monday, July 2, 2012

How to Add and Remove item in DropDownList using JQuery?

DropDownList – 

DropDownList is a control which is used for showing collection of items on the web page. We can bind DataSource to DropDownList control also, It has some inbuilt methods like Add () and Remove (), using these method we can perform Insertion and deletion operations on DropDownList's items. But these methods are server side methods.

In some of the cases we want to perform Insertion and deletion operation on DropDownList's items on client side means we don't want to perform server side functionality for this, In this article , I am explaining - How to Add and Remove item in DropDownList using JQuery?

For this, I have designed page like this-

.aspx code-
                        <asp:Button ID="btnAdd" runat="server" Text="Add Item" OnClientClick="return funInsert();" />
                    <td colspan="2" align="center">
                        <asp:DropDownList ID="drpList" runat="server" Width="100">
                            <asp:ListItem Value="1">a</asp:ListItem>
                            <asp:ListItem Value="2">b</asp:ListItem>
                            <asp:ListItem Value="3">c</asp:ListItem>
                        <asp:Button ID="btnDelete" runat="server" Text="Remove Item" OnClientClick=" return funDelete();" />

Now to perform insertion and deletion operation on DropDownList's Items, I have defined two client side functions-

1. funInsert() - For Insertion operation
2. funDelete() - For deletion operation
   <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        //Function to insert item to DropDownList
        function funInsert() {
            var item = prompt("Enter Item to add- ");
            if (item == null) {
                alert("First enter item");
            else {
                var count = $("#<%= drpList.ClientID  %> option ").length;

                //Adding item to DropDownList
                $("#<%= drpList.ClientID %>").append("<option value=" + (parseInt(count) + parseInt(1)) + ">" + item + " </option>");
            return false;

        //Function to remove item from DropDownList
        function funDelete() {
            var count = $("#<%= drpList.ClientID  %> option ").length;
            if (count == 0) {
                alert("No item to remove");
            else {
                //Removing item from DropDownList
                $("#<%= drpList.ClientID %> option[value=" + count + "]").remove();

            return false;

In above code, to perform Insertion operation on items, I have defined funInsert() function.
Here for inserting new item, I am prompting the user for entering new item as input using prompt ().

Like this-
Enter New Item

After getting input from user, I am inserting this item to the DropDownList using append () method.

Like this-

  //Adding item to DropDownList
                $("#<%= drpList.ClientID %>").append("<option value=" + (parseInt(count) + parseInt(1)) + ">" + item + " </option>");

   Here "item" is variable which is representing entered item by user. After executing this code item will be added to DropDownList.

Like this-
Add Item

In image you can see newly added item.

 Now to delete item from DropDownList, I have defined one client side function-   funDelete().
 In this function, I have written code to delete last item from the DropDownList. For this first I am getting count of items as "count" variable.

To delete item I have used this code-

  //Removing item from DropDownList
                $("#<%= drpList.ClientID %> option [value=" + count + "]").remove();

Here I have used remove() method, For this first I have got last item using JQuery and deleted that item using remove() method.

Like this-
Delete Item
You can see image last item- "New Item4" has been deleted from the DropDownList.

Note- I have used JQuery for this functionality, so it is must that JQuery plug-in should be included on the page, like I have included on top of the page.