Friday, April 29, 2011

Interview Questions IG - 8

1) What is Json?

2) Why we use Json?

3) Joins - Left Outer, Right Outer, Full Outer, Inner Join?

4) Why we use static method?

5) Give me real example where you use static method.

6) If we have a table in which thousands of record inserting,deleting and updating daily. Which tyhpe of index you will use there.

7)Any critical job/work that you have done so far?

8) Difference between clustered and non clustered index.

9) What is identity?

10) What is scope identity?

11) Is it make sense that we define clustered index on primary key column.

12) Can we define clustered index on composite column?

Friday, April 22, 2011

Interview Questions MMT -7

1) Difference between WebFarm and WebGarden.

2) Session is best in WebGarden Scenario?

2) Three differences between PrimaryKey and UniqueKey.

Answer. 1. Primary key is only one in table while unique key can be multiple
2. unique key can be null
3. cluster index create on primary key while non cluster index can be created on non cluster index.

3)What is Currency Control?

4) Where we use Currency Control?
a) Forms b) Control c) Both d) None

5)What is the use of Server.Execute?

6) Default in web.config file.
Answer : Anonymous access

7)Do we need to stop IIS before installing new version of an assembly?

8)Which file is used to define Resource Info ?
a) Web.config b) Global.asax c) Both d) None

9)If you want to get Forms Collection what will you use?
a) Response.Redirec b) Server.Transfer c) Server.Execute d) None e) All

10)Thread is a
a) Event b) Object c) Instance Method d) Static Method

11)Which can not be new?
a) DataReader b)DataTable c) DataRow d) DataColumn

12)How will you bind a text box with dataview?
a) Text1.Databinding(dv,"EmpNo")
b) Text1.Databinding(dv)
c) Text1.Databinding("EmpNo")
d) None

13)Which is wrong?
a) You can find data in dataview if dataview is sort only.
b) Dataview is a subset of rows and columns.
c) None
d) Both

14) ConnectionPool access in case of
a) Connection Close b) Connection Dispose c) Connection Life time expired d) All

15) Pessimistic lock used when
a) High Contention
b) Lock cost is low than Rollback
c) Lock cost is high than Rollback
d) All
e) None

16)Session objects are accessible in?

a) web forms b) 2. web Garden c) both d) none

Answer. web forms – check once

17) Application objects are accessible in?

a) web forms b) Web Garden c) both d) none

Answer. a. web forms

18)Which control have the paging?

a) dataset b) datareader c) None d) All
Answer. dataset

19)Which file contains the configuration settings for URI to access in web services?
Answer. .disco (check it once)

20) I have a datagrid/Gridview can i have a dropdown inside a column and binding to different dataset?
Answer : Yes, using template field

21) How will you fill a dropdown from another dataset and grid from another dataset.
Answer: Fill the grid first than on RowDatabound event find the combo control and bind it with another dataset.

22) How will you add increasing number (index numbers of rows) in datagrid without bringing it from database.

Answer : using rowdatabound

23) Suppose there is two button in a datagrid column. how will you identify which button is clicked?
Answer : using command name and command argument

24) How many nulls unique key can have?
Answer : Only one

25) Can we define unique key on combination of keys?
Answer : yes

Friday, April 15, 2011

eval in javascript

1) eval is used to evaluate the expression.
Example:

var iValue =10;
document.write(eval(iValue+10));
eval("iFirst=10;iSecond=20;document.write(iFirst*iSecond)");

Output:
20
200

2) eval used to reduce the number of lines.

Suppose you are doing some validation part.
Without eval

if (document.myForm.Name.value.length==0)
{
alert("Name requires a value");
}

if (document.myForm.Salary.value.length==0)
{
alert("Salary requires a value");
}

Using eval

var fieldList = new Array('Name','Salary');
var tempObj;

for (count=0;count<fieldList.length;count++)
{
tempObj=EVAL("document.myForm." + fieldList[i]);
if (tempObj.value.length==0)
{
alert(fieldList[i] + " requires a value");
}
}

3) eval can be used to generate dynamic variable.

eval("iValue" + iIndex);
Same way we can use window["iValue"+ iIndex]

Friday, April 8, 2011

Interview Questions -- RG-6

1) What about security in web services?
Never Implemented

2) How will you overload methods in web services?

3) What is the use of eval function?

4) What is XMLHTTP Object?

5) If you have two xml with same structure and we have to create single with distinct daata. How will you do that?

6) If there are duplicate rows in data table how will you get distinct row in ADO .Net and SQL server.

7) Have you used SQL Profiler?

8) Static vairables in C#?

9) Difference between Dispose and Finalizer/

10)What is clustered index?

11) What will you do improve the perfonace ofa page?

12) What is difference between dataset and DataReader.

13) If you have two millions rows in database than whihc one you will use dataset or datareader?

14) What is the use of yield keword?

15) What is dispathcer?

16) Which interface do you use in Remoting?

17) How will you use SOAP Header in Web Services?

Wednesday, April 6, 2011

Ranking Functions in SQL Server

In Oracle we had rownum function which was used to assign a number for each row. Same way, SQL Server 2005 introduce four Ranking functions to assign a number to each row. Each function has unique features. Let’s discus in detail.

Ranking functions allow you sequentially number your result set. There are four Ranking function.

1) Row_Number() :- Returns the Sequential number for each row in increasing order start from 1.

Syntax : Row_Number() over(partition_clause|order_by_clause)

Suppose you have table named Employee
Table 1
Name                Age              Sex
Asim                20                M
Amir                20                M
Anas                24                M
Shabnam             17                F
Shradha             19                F
Rachna              21                F

Use RowNumber() with order by clause.

Select ROW_NUMBER() over(order by Age) as RowNumber,Name,Age,Sex from Employee

Table 2
RowNumber          Name          Age          Sex
1                 Shabnam        17            F
2                 Shradha        19            F
3                 Asim           20            M
4                 Amir           20            M
5                 Rachna         21            F
6                 Anas           24            M


If you don’t want to sort the table but want the data with RowNumber you can use Select 1 statement as Row_Number required order by clause

Select ROW_NUMBER() over(order by (Select 1)),Name,Age,Sex from Employee

Table 3
RowNumber          Name          Age         Sex
1                  Asim          20           M
2                  Amir          20           M
3                  Anas          24           M
4                  Shabnam       17           F
5                  Shradha       19           F
6                  Rachna        21           F


-- Use Row Number with partition by clause
Select ROW_NUMBER() over(partition by Sex order by age),Name,Age,Sex from Employee

Table 4
RowNumber          Name          Age          Sex
1                 Shabnam        17            F
2                 Shradha        19            F
3                 Rachna         21            F
1                 Asim           20            M
2                 Amir           20            M
3                 Anas           24            M

--You can not use Row_Number without order by clause
Select ROW_NUMBER() over(),Name,Age,Sex from Employee

Msg 4112, Level 15, State 1, Line 1
The ranking function "ROW_NUMBER" must have an ORDER BY clause.

May be you have noticed one thing in above tables Amir and Asim have same age but have different row number. If you want the same sequence number for rows that have same value than you have to use rank function for this. But it leave a gap between sequence number.
For an example we have same value for Amir and Asim 20,20. Sequence number for Asim and Amir is 3 but sequence number for Rachna is 5. (4 is missing here you can say draw back or advantage of rank function according to your requirement).

-- Use rank() with order by caluse
Select rank() over(order by Age) as RowNumber,Name,Age,Sex from Employee

Table 5
RowNumber          Name          Age          Sex
1                 Shabnam        17            F
2                 Shradha        19            F
3                 Asim           20            M
3                 Amir           20            M
5                 Rachna         21            F
6                 Anas           24            M


There is no use of Select 1 statement with rank function as it will give you 1 for all row in the table.

Select rank() over(order by (Select 1)),Name,Age,Sex from Employee

Table 6
RowNumber          Name          Age         Sex
1                  Asim          20           M
1                  Amir          20           M
1                  Anas          24           M
1                  Shabnam       17           F
1                  Shradha       19           F
1                  Rachna        21           F

partition clause also can use with rank function also output will be same as for RowNumber except one thing. All rows having same value will assign same number.

-- Use rank() with partition by clause
Select rank() over(partition by Sex order by age),Name,Age,Sex from Employee

Table 7
RowNumber          Name          Age          Sex
1                 Shabnam        17            F
2                 Shradha        19            F
3                 Rachna         21            F
1                 Asim           20            M
1                 Amir           20            M
3                 Anas           24            M

order by clause is must for rank function also.

If you will see the above tables(for rank), you will notice a gap between numbers. In table 4 Rachna has sequence number 5 which should be 4. for this you can use dense_rank(). It same as rank but it did not leave the gap.

-- Use dense_rank() with order by clause
Select dense_rank() over(order by Age) as RowNumber,Name,Age,Sex from Employee.

Table 8
RowNumber          Name          Age          Sex
1                 Shabnam        17            F
2                 Shradha        19            F
3                 Asim           20            M
3                 Amir           20            M
4                 Rachna         21            F
5                 Anas           24            M

all others would change as well.

Have you missed one thing so far, yes grouping with sequence number. SQL server provide a function name NTILE(TOTAL_GROUP_NUMBER). NTILE function divide the table in groups as many you have given in braces(TOTAL_GROUP_NUMBER). And than assign the same number for each member of the same group.

Let’s see the example for detail. Suppose you want to divide the given table in 3 groups than the query will be.

-- Use NTILE(3) with order by caluse
Select NTILE(3) over(order by Age) as RowNumber,Name,Age,Sex from Employee

Table 9
RowNumber          Name          Age          Sex
1                 Shabnam        17            F
1                 Shradha        19            F
2                 Asim           20            M
2                 Amir           20            M
3                 Rachna         21            F
4                 Anas           24            M



NTILE first divide the Total Rows by Total Group Number. And calculate how many rows should be come in one group.

Here group number is 3 and Total Rows are 6 So there will be 6/3 =2 rows in each group.

NTILE start making group from start and assign the same number for each row of the group. In above example Shabnam and Shardha are in the same group it has assign the same number that is 1 (starting number), Asim and an Amir are in the second group and have the same sequence number that 2. , Rachna and Anas are in the third group number that is 3.

It makes the group on the basis of FCS.

You will give Group number 6 than output will be different. In this case Total Rows in each groups is 6/6=1.

Table 10
RowNumber          Name          Age          Sex
1                 Shabnam        17            F
2                 Shradha        19            F
3                 Asim           20            M
4                 Amir           20            M
5                 Rachna         21            F
6                 Anas           24            M

Total group number may less ,equal or greater than total number of rows in table.


Other queries can be checked as well

-- If you don't want to sort the table but want the data with NTILE(3) you can use Select 1 statement as rank required order by clause
Select NTILE(3) over(order by (Select 1)),Name,Age,Sex from Employee

-- Use NTILE(3) with partition by clause
Select NTILE(2) over(partition by Sex order by age),Name,Age,Sex from Employee

You can download the complete script : Rankning Functions

Friday, April 1, 2011

Master Page Life Cycle

Page Life Cycle with Master Page

When we use Master Page in our application than it affects the Life Cycle of the page. There are two types of event one is for controls of the page and second one is for page itself. Controls event always fired before Page event except two exceptions cases Load and PreRender. These two events fired before controls corresponding event. Same is true for Content and Master, Master Page event fired before Content's event except these two cases.


1) Master Controls Init
2) Content Controls Init

3) Master Page Init
4) Content Page Init

5) Content Page Load
6) Master Page Load

7) Master Controls Load
8) Content Controls Load

9) Content Page PreRender
10) Master Page PreRender

11) Master Control PreRender
12) Content Control PreRender

13) Master Controls Unload
14) Content Controls Unload

15) Master Page Unload
16) Content Page Unload

Followers

Link