Friday, March 28, 2008

Question for Dot Net Interview (Part 7):

--* What is Data Binding?
Data binding is a way used to connect values from a collection of data (e.g. DataSet) to the controls on a web form.

--* Describe the difference between inline and code behind.
1)Inline code is written along side the HTML in a page.
2)Code-behind is code written in a separate file and referenced by the .aspx page


--* What is the transport protocol you use to call a Web service?
SOAP (Simple Object Access Protocol) is the preferred protocol.

--* What is database replicaion
Replication is the process of copying/moving data between databases on the same or different servers

--* What are the different types of replication?
1) Transactional
2) Snapshot
3) Merge


--* What is the difference among “dropping a table”, “truncating a table” and “deleting all records” from a table.

* Dropping : (Table structure + Data are deleted), Invalidates the dependent objects ,Drops the indexes
* Truncating: (Data alone deleted), Performs an automatic commit, Faster than delete
* Delete : (Data alone deleted), Doesn’t perform automatic commit


--* BulkCopy is a tool used to copy huge amount of data from tables

--* Types of Trigger:
Inserted and Deleted.


--* What is SQL Profiler?
SQL Profiler is a graphical tool that allows system administrators to monitor events in an instance of Microsoft SQL Server


--* What is User Defined Functions?
User-Defined Functions allow to define its own T-SQL functions that can accept 0 or more parameters
and return a single scalar data value or a table data type

Question for Dot Net Interview (Part 6):

--* What is the difference between Dataset.clone() and Dataset.copy()?
1) Dataset.clone() --> Copy only structure (Returns a DataSet with the same structure (tables andrelationships) but no data.)
2) Dataset.copy() --> Copy Structure & Data Both (Returns an exact duplicate of the DataSet, with the same set of tables, relationships, and data.)

--* What is the difference between autopostback and ispostback?
1) Autopostback - Property of the control
2) IsPostback - Property of the Page class

--* What is the difference between ExcuteQuery and ExcuteNonQuery ?
1) ExcuteQuery used with select statement
2) ExcuteNonQuery used with insert ,update ,delete statement
3) ExcuteNonQuery return number of row affected
4) ExcuteQuery return one or more row of data

--* What is Tracing :
Trace in ASP.Net is nothing but to trace error and It will also give some details of the error, so that the user can easily debug the code.

--* Types of Tracing :
1) Application Level Tracing
2) Page Level Tracing

--* Different types of style sheets:
1) External
2) Inline

--* Viewstate : stores the state of controls in HTML hidden fields.

--* Can we run asp.net apllication without WEB.CONFIG file?
YES , Because all the configuration settings will be available under MACHINE.CONFIG file

--* Session state is global to your entire application for the current user. Session state can be lost in several ways:
1) If the user closes and restarts the browser.
2) If the user accesses the same page through a different browser window, although the session will still exist if a web page is accessed through the original browser window. Browsers differ on how they handle this situation.
3) If the session times out because of inactivity. By default, a session times out after 20 idle minutes.
4) If the programmer ends the session by calling Session.Abandon().

--* A transactionis:- a set of operations that must either succeed or fail as a unit. The goal of a transaction is to ensure that data is always in a valid

--* Types of Data Source in the.NET Framework:
1) SqlDataSource: This data source allows you to connect to any data source that has an ADO.NET data provider
2) ObjectDataSource: This data source allows you to connect to a custom data access class
3) XmlDataSource : This data source allows you to connect to an XML file
4) SiteMapDataSource: This data source allows you to connect to the Web.Sitemap file that describes the navigational structure of your website

--* Types of ADO.Net Data Provider:
1) System.Data.SqlClient
2) System.Data.OracleClient
3) System.Data.OleDb
4) System.Data.Odbc

--* What are types of sub queries :
1) Single row subquery
2) Multiple row subquery
3) Multiple column subquery

--* What command do we use to rename a Database sp_renamedb ‘oldname’ , ‘newname’

--* What is the command that we use to install IIS after you installed ASP.NET aspnet_regsql -i

--* What is the purpose of @@Identety:
Returns the last identity value inserted as a result of the last INSERT or SELECT INTO statement.

--* Describe the difference between inline code and code behind.
1) Inline code written along side the html in a page.
2) Code-behind is code written in seprate file and refrenced by .aspx in page.

--* What is the difference between System.Array.CopyTo and System.Array.Clone in .NET?
1) The Clone() method returns a new array object containing all the elements in the original array.
2) The CopyTo() method copies the elements into another existing array.

--* What is Encapsulation?
Encapsulation - is the ability of an object to hide its data and methods from the rest of the world. It is one of the fundamental principles of OOPs

--* Who is a protected class-level variable available to?
It is available to any sub-class (a class inheriting this class).

--* Describe the accessibility modifier “protected internal”.
It is available to classes that are within the same assembly and derived from the specified base class

--* What’s the difference between the Debug class and Trace class?
1) Use Debug class for debug builds,
2) use Trace class for both debug and release builds

--* Explain the differences between public, protected, private and internal.
1) Public: Allows class, methods, fields to be accessible from anywhere i.e. within and outside an assembly.
2) Private: When applied to field and method allows to be accessible within a class.3) Protected: Similar to private but can be accessed by members of derived class also.
4) Internal: They are public within the assembly i.e. they can be accessed by anyone within an assembly but outside assembly they are not visible.

--* List the event handlers that can be included in Global.asax?
1) Application start and end event handlers
2) Session start and end event handlers
3) Per-request event handlers
4) Non-deterministic event handlers

--* What’s a strong name?
A strong name includes: the name of the assembly, version number, culture identity, and a public key token.

--* What is constructor.
Constructor is a method in the class which has the same name as the class It initialises the member attributes whenever an instance of the class is created.

--* What is difference between CHAR and VARCHAR:
1) CHAR pads blank spaces to the maximum length.
2) VARCHAR2 does not pad blank spaces.
3) For CHAR the maximum length is 255 and 2000 for VARCHAR

--* What are the four types of events ?
1. System Events.
2. Control Events
3. User Events
4. Other Events

--* How many Global.asax files can an Application have?
Only one Global.asax file and it’s placed in the virtual directory’s root

--* What is a session?
A user accessing an application is known as a session.

--* Different between Local and Global Variable:
1) A variable is global if it is declared outside of the main program block and not within a function
2) A variable is local if it is declared between the function declaration
3) Global variables are visible and available to all statements in a setup script that follow its declaration
4) Local variables are visible and available only within the function where they are declared.

--* Difference Between EXE and DLL file :
1) Exe is the Application
2) DLL is the Component
3) Exe can execute on its own
4) DLL Can not execute on its own
5) EXE can run independently
6) DLL will run within an Exe
7) EXE is an out-process file
8) DLL is an in-process file

--* Difference between Strong and Weak type
1) Strong type: Checking the types of variables at compile time
2) Weak type: Checking the types of variables at run time.

--* Difference between Function and Stored Procedure:
1) Function returns only one Value
2) Stored Procedure can return many value or not return
3) Functions Must return a value, procedures doesn't need to
4) Functions can be used within a Stored Procedure but stored procedures cannot be used within a function

--* How to kill session?
use session.abandont method

--* What are the different types of cookies
1) Persistent Cookies.
2) Non Persistent CookiesPersistent cookies are those which is storing in cookies folder in hard disk.Non persistent cookies is created on memory, inside the browser process. When we close the browser, that memory region will collect by Operating system, and the cookie will also deleted.

--* Write the HTML for a hyperlink that will send mail when the user clicks the link.
Send mail

Monday, January 21, 2008

Send Email using ASP.Net














Create a web page

and in Default.aspx.cs add the following code:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
namespace Email
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblFrom;
protected System.Web.UI.WebControls.Label lblCC;
protected System.Web.UI.WebControls.TextBox txtFrom;
protected System.Web.UI.WebControls.TextBox txtCC;
protected System.Web.UI.WebControls.TextBox txtTo;
protected System.Web.UI.WebControls.Label lblTo;
protected System.Web.UI.WebControls.Label lblEmailService;
protected System.Web.UI.WebControls.TextBox txtBCC;
protected System.Web.UI.WebControls.Label lblBCC;
protected System.Web.UI.WebControls.Label lblSubject;
protected System.Web.UI.WebControls.TextBox txtSubject;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.TextBox txtMessage;
protected System.Web.UI.WebControls.Button btnSend;
protected System.Web.UI.HtmlControls.HtmlInputFile FileBrowse;
protected System.Web.UI.WebControls.Label lblAttachment;
protected System.Web.UI.WebControls.RadioButton rbtnAttach;
protected System.Web.UI.WebControls.RadioButton rbtnDetachment;
protected System.Web.UI.WebControls.Button btnCancel;
public string strAttachment;

private void Page_Load(object sender, System.EventArgs e)
{
lblMessage.Text="";
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.rbtnDetachment.CheckedChanged +=
new System.EventHandler(this.rbtnDetachment_CheckedChanged);
this.btnCancel.Click +=
new System.EventHandler(this.btnCancel_Click);
this.btnSend.Click +=
new System.EventHandler(this.btnSend_Click);
this.rbtnAttach.CheckedChanged +=
new System.EventHandler(this.rbtnAttach_CheckedChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion


//Method for sending the email
//***************************************************************
private void SendMail()
{
try
{
//Creating the Mail Message object.
MailMessage Email=new MailMessage();

//Storing the To value in the object reference.
Email.To=txtTo.Text;

//Storing the From value in the object reference.
Email.From=txtFrom.Text;

//Storing the CC value in the object reference.
Email.Cc=txtCC.Text;

//Storing the BCC value in the object reference.
Email.Bcc=txtBCC.Text;

//Storing the Subject value in the object reference.
Email.Subject=txtSubject.Text;

//Specifies the email body.
Email.Body=txtMessage.Text;

//Setting priority to the mail as high,low,or normal
Email.Priority=MailPriority.High;

//Formatting the mail as html or text.
Email.BodyFormat=MailFormat.Text;

//Checking whether the attachment is needed or not.
if(rbtnAttach.Checked)
{
//Adding attachment to the mail.
Email.Attachments.Add(
new MailAttachment(FileBrowse.Value));
}

//specifying the real SMTP Mail Server.
SmtpMail.SmtpServer.Insert(0,"127.0.0.1");
SmtpMail.Send(Email);//Sending the mail.

//calling the reset method to erase all the data
//after sending the mail.
Reset();
lblMessage.ForeColor=Color.Navy;

//User information after submission.
lblMessage.Text=
"*Your email has been sent successfully-Thank You";
}
//Catching Exception
catch(Exception exc)
{
Reset();
lblMessage.Text="Send error:"+exc.ToString();
lblMessage.ForeColor=Color.Red;
}
}

//Method to reset the text fields.
//***********************************************************
private void Reset()
{
//Seeking for the controls in the active webform.
Control myForm=Page.FindControl("Form1");

//Iterating each control.
foreach(Control ctl in myForm.Controls)
{
//Checking whether it is a text
//box and clear when it is a textbox.
if(ctl.GetType().ToString().Equals(
"System.Web.UI.WebControls.TextBox"))

((TextBox)ctl).Text="";
}
}

//Event fires for sending the mail.
//***********************************************************
private void btnSend_Click(object sender, System.EventArgs e)
{
SendMail();
}

//Event for cancelling the mail.
//***********************************************************
private void btnCancel_Click(object sender, System.EventArgs e)
{
Reset();
}

//Event for enabling or disabling the File browser.
//************************************************************
private void rbtnAttach_CheckedChanged(object sender,
System.EventArgs e)
{
FileBrowse.Disabled=false;
}

//Event for enabling or disabling the File browser.
//************************************************************
private void rbtnDetachment_CheckedChanged(object sender,
System.EventArgs e)
{
FileBrowse.Disabled=true;
}
//*************************************************************
}
}