Wednesday, November 24, 2010

SQL Star Telphonic

1) How do you achieve interoperatability?

2) What have you done in your module?
( I said that I worked on user authentication....)

3) I was asked about how a user can be authenticated.

4) Did you create authcookie? how you handle authecookie? I mean did you create it manually?
( I told him that there is method which take care of creating authcookie during authentication. That method is "RedirectFromLoginPage" . He replied me thats what he was expecting..

5) What is difference you observe between framework v2.0 and framework 3.5?

6) What are the different session management techniques? What method did you do in your project?

7) What is the difference between usercontrol and custom control?

FactorsUser controlCustom control
DeploymentDesigned for single-application scenarios

Deployed in the source form (.ascx) along with the source code of the application

If the same control needs to be used in more than one application, it introduces redundancy and maintenance problems
Designed so that it can be used by more than one application

Deployed either in the application's Bin directory or in the global assembly cache

Distributed easily and without problems associated with redundancy and maintenance
CreationCreation is similar to the way Web Forms pages are created; well-suited for rapid application development (RAD)Writing involves lots of code because there is no designer support
ContentA much better choice when you need static content within a fixed layout, for example, when you make headers and footersMore suited for when an application requires dynamic content to be displayed; can be reused across an application, for example, for a data bound table control with dynamic rows
DesignWriting doesn't require much application designing because they are authored at design time and mostly contain static dataWriting from scratch requires a good understanding of the control's life cycle and the order in which events execute, which is normally taken care of in user controls

8) Suppose you are implenting cache in a scenario where time is placed in cache and time shows different time for different time regions. How would you achieve this?
( I told that varyByParam property will take care of that..)

9)How page execution is done in asp.net?
(nothing but page life cycle..I forgot to tell page_unload event )

10) Can you pass parameters to command object?


11) you have a command object which executes a Storedprocedure. This SP takes x as parameter and y as output parameter. I want to show the output return by the SP on the aspx page.


Use a Stored Procedure which takes empid as input parameter and returns depid of that employee. For this take a dropdown with collection of employees. When selecting an item in dropdown, it will give the deptid of that selected employee in dropdown.

First create SP which takes one i/p and gives one o/p parameters..

CREATE PROCEDURE SP_Test(@EmpID int,@DeptID int OUTPUT)
AS
BEGIN
SELECT @DeptID = DeptID FROM MY_EMP_DETAILS WHERE EmpID=@EmpID
END

Execution of the above SP for testing...

DECLARE @Dept INT
EXEC SP_TEST 15, @Dept OUTPUT
PRINT @Dept

======================================

using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{

SqlConnection SqlCon = new SqlConnection("server=servername;database=databasename;user id=sa;password=xxx");
SqlCommand SqlCom;

protected void Page_Load(object sender, EventArgs e)
{
//fill the employee dropdown...
if (!IsPostBack)
{
SqlCon.Open();
SqlCom = new SqlCommand();

SqlCom.Connection = SqlCon;
SqlCom.CommandText = "select EmpID, EmpName from MY_EMP_DETAILS";
SqlCom.CommandType = CommandType.Text;

DataSet ds=new DataSet();
SqlDataAdapter SqlDa = new SqlDataAdapter(SqlCom);
SqlDa.Fill(ds);

SqlCon.Close();

ddlEmp.DataValueField = ds.Tables[0].Columns["EmpID"].ColumnName;
ddlEmp.DataTextField = ds.Tables[0].Columns["EmpName"].ColumnName;
ddlEmp.DataSource = ds;
ddlEmp.DataBind();
}

}

protected void ddlEmp_SelectedIndexChanged(object sender, EventArgs e)
{

SqlCom = new SqlCommand();
SqlCom.Connection = SqlCon;

//Input parameter declaration...
SqlCom.Parameters.Add("@EmpID", SqlDbType.Int);
//Output parameters declaration....
SqlCom.Parameters.Add("@DeptID", SqlDbType.Int);

SqlCom.CommandText = "SP_Test";
SqlCom.CommandType = CommandType.StoredProcedure;

SqlCom.Parameters["@EmpID"].Value = ddlEmp.SelectedValue;
//Must specify direction for output parameter in Storedprocedure...
SqlCom.Parameters["@DeptID"].Direction = ParameterDirection.Output;

SqlCon.Open();
SqlDataReader dr= SqlCom.ExecuteReader(CommandBehavior.CloseConnection);
dr.Close();

Response.Write("Employee " + ddlEmp.SelectedItem.Text + " Department ID is " + SqlCom.Parameters["@DeptID"].Value.ToString());

}
}
Note: use the link given to know various ways of returning values from a StoredProcedure..
http://www.4guysfromrolla.com/articles/062905-1.aspx#postadlink

12) How do you fill the datatable in dataset using datareader?
(I told that create a table object, create a new row, fill the datareader values into newrow. All this is done in while loop which takes dr.read() as a condition...He again said that this is what he is expecting from his question..)

13) How you choose an interface and an abstract class?

14) What is httpHandler and httpMethods?

15) ADO.NET Architecture?





















16) I have a parent class and one child class which is inhertted from parent class. Now I write Parent class Obj =new parent class(). Is this give any Error?
( I said no and he asks again on that..)

17) I have like parent class Obj = new child class(). Is this gives any error?
(I said its perfectly working..)

18) I have like child class obj = new parent class(). Is this gives any error?
( I said I am not sure...but I think it gives error...)
(Actually thing is that, the above line is correct if you cast new parent class object in to child class..otherwise it gives compile error..)

19) What is boxing and un-boxing?

20) What is cross page posting. How do you achieve it?

21) What is partial class. What is the use of that?

22) I dont want to store user credentials in database or xml file. Can you tell me the other way of storing them?

23) Did you give password in plain text in web.config file? If not, how do you do that?

24) What is the difference between string and String?

Both are same. Just one is alias for the other. For declaring String, you need using System namespace where as string doesnot require any namespace to use.

25) Where do you set master page dynamically? Which property do you use to set it?

In the PreInit event, we can set the master page dynamically. Using the 'MasterPageFile' property we assign the master page. Here is a piece of code....

void Page_PreInit(Object sender, EventArgs e)
{
    this.MasterPageFile = "~/NewMaster.master";
} 
26) What is the difference between Server.Transfer and Response.Redirect? 

Tuesday, November 23, 2010

Semantic Telephonic and Face To Face


Telephonic

Oops
  1. what is runtime polymorphism?
Run time Polymorphism
  • Run time Polymorphism also known as method overriding
  • Method overriding means having two or more methods with the same name , same signature but with different implementation

2. Can you achieve runtime polymorphism in Interfaces?

No...

interface AAAA
{
void BaseIntMethod();
}
interface BBBB:AAAA
{
void BaseIntMethod();
}

The above code will compile but it gives a warning message like
'BBBB.BaseIntMethod()' hides inherited member 'AAAA.BaseIntMethod()'. Use the new keyword if hiding was intended.


3) suppose there is ClassA with virtual method AAA() and ClassB is inheritted from ClassA and override the method AAA().
ClassA Obj = new ClassB().
By using Obj, which method can be called? method in ClassA or method in ClassB?

public class AAAA
{
public virtual void MethodAAA()
{
MessageBox.Show("Method in AAA");
}
}
public class BBBB:AAAA
{
public override void MethodAAA()
{
MessageBox.Show("Method in BBB");
}
}

AAAA Obj = new BBBB();
Obj.MethodAAA();

OutPut: “Method in BBB”

public class AAAA
{
public virtual void MethodAAA()
{
MessageBox.Show("Method in AAA");
}
public void AnotherMethodInAAA()
{
}
}
public class BBBB:AAAA
{
public override void MethodAAA()
{
MessageBox.Show("Method in BBB");
}
public void AnotherMethodInBBB()
{

}
}

CASE #1

Usage of above code and behaviour of the Object.
Observe in this scenario you are unable to call normal method in Class BBBB. I.e: AnotherMethodInBBB()

CASE #2
Here MethodAAA() is the overide method in Class BBBB.

4)Can we override methods in interfaces?

Yes..the following code works fine..

interface Iinterface
{
void Imethod();
}

public class AAAA : Iinterface
{
public virtual void Imethod()
{
}
}
public class BBBB : AAAA
{
public override void Imethod()
{
}
}

  1. what is garbage collector?
Garbage collector manages the allocation and release of memory for your application.

Each time you create a new object, the common language runtime allocates memory for the object from the managed heap. As long as address space is available in the managed heap, the runtime continues to allocate space for new objects. However, memory is not infinite. Eventually the garbage collector must perform a collection in order to free some memory. The garbage collector's optimizing engine determines the best time to perform a collection, based upon the allocations being made. When the garbage collector performs a collection, it checks for objects in the managed heap that are no longer being used by the application and performs the necessary operations to reclaim their memory.


  1. what is generic collections?
List is a generic collection. Lists are dynamic arrays in the C# language. They can grow as needed when you add elements.They are considered generics and constructed types.


  1. what are anonymous methods?
An anonymous method is a method without a name - which is why it is called anonymous.You don't declare anonymous methods like regular methods. Instead they get hooked up directly to events. Because you can hook an anonymous method up to an event directly, couple of the steps of working with delegates can be removed. An anonymous method uses the keyword, delegate, instead of a method name.

 public Form1()
    {
        Button btnHello = new Button();
        btnHello.Text = "Hello";

        btnHello.Click +=
            delegate //anonymous method
            {
                MessageBox.Show("Hello");
            };

        Controls.Add(btnHello);
    }
  1. what is delegate? how it can be used?
A delegate is a type-safe object that can point to another method (or possibly multiple methods) in the application, which can be invoked at later time.

public class MyClass
{
public static int AddNos(int x, int y)
{
return x + y;
}
public static int MultiplyNos(int a, int b)
{
return a * b;
}
}

//Declaring a Delegate...
public delegate int MyAddDelegate(int x1,int x2);

Using a delegate...

private void button1_Click(object sender, EventArgs e)
{
//Create a Delegate Object and Points it to a method...

MyAddDelegate ObjDel = new MyAddDelegate(MyClass.AddNos);

//Calling method using Delegate Object......

int iAdResult = ObjDel(25, 25);

MessageBox.Show(iAdResult.ToString());

MyAddDelegate ObjDlg = new MyAddDelegate(MyClass.MultiplyNos);
int iMulResult = ObjDlg(25, 25);
MessageBox.Show(iMulResult.ToString());
}

Multicast delegates....

public class MyClass
{
public static void AddNos(int x, int y)
{
MessageBox.Show((x + y).ToString());
}
public static void MultiplyNos(int a, int b)
{
MessageBox.Show((a*b).ToString());
}
}
//Declaring a Multicast Delegate...
public delegate void MyDelegate(int x1,int x2);

//Using Multicast delegate...
private void button1_Click(object sender, EventArgs e)
{
//Create a Delegate Object and Points it to a method...
MyDelegate ObjDel = new MyDelegate(MyClass.MultiplyNos);

//Adding another method to the Same delegate Object....
ObjDel += new MyDelegate(MyClass.AddNos);
//Calling the two methods using delegate..
ObjDel(25, 25);

//Removing one method from delegate...
ObjDel -= new MyDelegate(MyClass.AddNos);
ObjDel(12, 12);
}

OutPut: 625,50,144

Note:The Multicast delegate here contain methods that return void, if you want to create a multicast delegate with return type you will get the return type of the last method in the invocation list.

  1. what is an event? how it can be handled?
public class EventClass
{
//Declaring a Delegate...
public delegate void MyDelegate(int x, int y);

//Declare an Event of Type MyDelegate..
public event MyDelegate MyEvent;

public void AddMethod(int a, int b)
{
MessageBox.Show("Adding of given Nos" + " " + (a + b).ToString());
}

public void RaiseEvent(int x1, int x2)
{
if (MyEvent != null)
MyEvent(x1, x2);
}
}

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
EventClass ObjCls = new EventClass();
//Create a delegate object which holds the method...
EventClass.MyDelegate ObjDel = new EventClass.MyDelegate(ObjCls.AddMethod);

ObjCls.MyEvent += ObjDel;

ObjCls.RaiseEvent(12, 15);
}
}

  1. what is serialization? Types of serialization?
Converting objects into stream of bytes.

Binary Serialization:

using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace BinarySerilization
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
MyClass Obj = new MyClass();
Obj.sAuthor = "Sekhar";
Obj.sPublisher = "McGrawHill";
Obj.sBookName = "DotNetFundas";

Obj.SerializeObject(@"C:/123.txt");

MyClass MyObj = Obj.DeSerializeObject(@"C:\123.txt");
MessageBox.Show(MyObj.sAuthor);
MessageBox.Show(MyObj.sPublisher);
MessageBox.Show(MyObj.sBookName);

}
}

[Serializable()]
public class MyClass:ISerializable
{
public MyClass()
{
}

public string sAuthor;
public string sPublisher;
public string sBookName;

//Implement method in Iserializable for placing object stream into local disc...
public void GetObjectData(SerializationInfo sInfo, StreamingContext sStrmCntxt)
{
sInfo.AddValue("Author", sAuthor);
sInfo.AddValue("Publisher", sPublisher);
sInfo.AddValue("Book", sBookName);
}

//Override constructor to get an object from stream saved in the local disc...
public MyClass(SerializationInfo sInfo, StreamingContext sStrmCntxt)
{
sAuthor = (string)sInfo.GetValue("Author", typeof(string));
sPublisher = (string)sInfo.GetValue("Publisher", typeof(string));
sBookName = (string)sInfo.GetValue("Book", typeof(string));
}

//method for serializing object...
public void SerializeObject(string sFileName)
{
FileStream fs = new FileStream(sFileName, FileMode.CreateNew, FileAccess.ReadWrite);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, this);//form here control goes to GetObjectData() method to collect serialization info...
fs.Close();
}

//method for Deserializing object....
public MyClass DeSerializeObject(string sFileName)
{
FileStream fs = new FileStream(sFileName, FileMode.Open, FileAccess.Read);
BinaryFormatter bf = new BinaryFormatter();
MyClass Obj = (MyClass)bf.Deserialize(fs);//from here control goes to Overloaded Constructor MyClass()...
fs.Close();
return Obj;
}
}
}

XML Serialization

[XmlRoot("Class_Person")]
public class Person
{

private string _Name;
private int _Age;

[XmlElement("Prop_Name")]
public string Name
{
get {return _Name;}
set{_Name=value; }
}

[XmlElement("Prop_Age")]
public int Age
{
get { return _Age; }
set { _Age = value; }
}
}

private void button1_Click(object sender, EventArgs e)
{
//Serializing the object...
XmlSerializer XmlSer = new XmlSerializer(typeof(Person));

StreamWriter strWrt = new StreamWriter(@"C:\123.xml");
Person ObjPer = new Person();
ObjPer.Name = "Sekhar Peddagopu";
ObjPer.Age = 27;

XmlSer.Serialize(strWrt, ObjPer);

//Deserializing the object...
XmlSerializer XmlSerial = new XmlSerializer(typeof(Person));
StreamReader strRdr = new StreamReader(@"C:\123.xml");
Person AnotherObj = (Person)XmlSerial.Deserialize(strRdr);

MessageBox.Show("Name of Person" + AnotherObj.Name.ToString() + "___" + "Age:" + AnotherObj.Age.ToString());

}


Asp.net

1) what is client server mechanism works in asp.net and window apps?

2) what is session? how session is managed by webserver? if session is outproc then what is the seralization done in that case? How state server manage session? How state server used?

3) How seesion is manage when session mode is outproc?

4) what is webservice? how it is used in application? what proxy can contain?

5) what is xsd?

6) What is styles and theme?

Sql server

1) Types of index? How storage is done in both?

2) Difference between SP and Fn?

  1. Difference between Char, VarChar and nVarChar?
  • Nvarchar stores Unicode data (two bytes for each character) while varchar stores single-byte character data.
  • nvarchar requires twice the storage space as varchar.
  • Main reason for preferring nvarchar over varchar would be internationalization (i.e. storing strings in other languages).
2nd Round F to F

1) How do you maintain your session in your e-commerce application? Is it Inproc or outproc?

2) Did you write any javascript in your code? Why do you make validations using javascript without using asp.net validation controls.

3) How do you pass user name and password to server from aspx page?

4) What is serialization and why do you need it? How do you serialize objects?

5) what is Ienumerable interface?

6) How do you type cast user defined data types? Have ever heard 'is' and 'as' keywords?

7) Have you ever create index? What is its purpose?

8) what compile code can contain? what CLR does?

9) What components can contain? how do you use components in your code?

10) How did you implement Ooops in your project?

11) In which scenarios Interface and Abstract class can be used?

12) How do you copy an object? How do you clone object?

13) What is cursor?

  1. What is temp table?
Temporary tables provide a way to organize data derived from queries into new tables, which can themselves be queried repeatedly over the lifetime of a MySQL user session. It is also used to hold the results of a called stored procedure .

The syntax to create a temporary table is exactly same as the syntax to create a normal table. But the difference is the table name is prefixed with '#' (pound). By looking at the prefix '#' the sql server understands that it is a temporary table. The following code demonstrates how to create a temporary variable.

CREATE TABLE #Customer
(
CustomerID int identity(1,1),
CustomerName varchar(100),
CompanyName varchar(100),
Address varchar(250)
)
It is almost similar to normal table with very few exceptions. The scope of the temp table is the current connection session. This table is automatically dropped when the connection session is closed. Foreign key relations cannot be applied to temp tables. When you create a temporary table it will be created in tempdb

  1. what is the difference in .net frameword 2.0 and .net framewor 3.5?


  1. Is CLR versions same for 2.0 and 3.5?

Yes...CLR version for 2.0 and 3.5 is same.

17) what is Linq? when you can use Linq in code?

18) In which case you use function and stored procedure?

19) Suppose two persons accessing one bank a/c same time. Both are shown by same balance? Using Dataset, how do you avoid concurrency exception?

20) what is basic difference between xml webservice and wcf?

21) what is runtime polymorphism?

22) what is difference between server.transfer and response.redirect?

23) Difference between dataset and datareader?

24) How do you contorl finalizer?

25) where is the view state available?

26) Where can you use functions?