Friday, June 12, 2009

@ page specific attribute in asp.net

@ Page
Defines page-specific (.aspx file) attributes used by the ASP.NET page parser and compiler.

<%@ Page attribute="value" [attribute="value"...] % Attributes >
AspCompat
When set to true, this allows the page to be executed on a single-threaded apartment (STA) thread. This allows the page to call STA components, such as a component developed with Microsoft Visual Basic 6.0. Setting this attribute to true also allows the page to call COM+ 1.0 components that require access to unmanaged Active Server Pages (ASP) built-in objects. These are accessible through the ObjectContext object or the OnStartPage method. The default is false.
Note Setting this attribute to true can cause your page's performance to degrade. For more information, see the Remarks section.
AutoEventWireup
Indicates whether the page's events are autowired. true if event autowiring is enabled; otherwise, false. The default is true. For more information, see Web Server Control Event Model.
Buffer
Determines whether HTTP response buffering is enabled. true if page buffering is enabled; otherwise, false. The default is true.
ClassName
Specifies the class name for the page that will be dynamically compiled automatically when the page is requested. This value can be any valid class name but should not include a namespace.
ClientTarget
Indicates the target user agent for which ASP.NET server controls should render content. This value can be any valid user agent or alias.
CodeBehind
Specifies the name of the compiled file that contains the class associated with the page. This attribute is used by the Visual Studio .NET Web Forms designer. It tells the designer where to find the page class so that the designer can create an instance of it for you to work with at design time. For example, if you create a Web Forms page in Visual Studio called WebForm1, the designer will assign the Codebehind attribute the value of WebForm1.aspx.vb, for Visual Basic, or WebForm1.aspx.cs, for C#. This attribute is not used at run time.
CodePage
Indicates the code page value for the response.
Note If you created your Web Forms page using a code page other than the default code page of the Web server on which the page will run, you must set this attribute. The value you enter should be the code page for the computer on which you created the page. For more information about code pages, search the Microsoft Developers Network (MSDN) at http://msdn.microsoft.com.
CompilerOptions
A string containing compiler options used to compile the page. In C# and Visual Basic .NET, this is a sequence of compiler command-line switches.
ContentType
Defines the HTTP content type of the response as a standard MIME type. Supports any valid HTTP content-type string. For a list of possible values, search for MIME in MSDN at http://www.microsoft.com/technet.
Culture
Indicates the culture setting for the page. For information about culture settings and possible culture values, see the CultureInfo class.
Debug
Indicates whether the page should be compiled with debug symbols. true if the page should be compiled with debug symbols; otherwise, false.
Description
Provides a text description of the page. This value is ignored by the ASP.NET parser.
EnableSessionState
Defines session-state requirements for the page. true if session state is enabled; ReadOnly if session state can be read but not changed; otherwise, false. The default is true. These values are case-insensitive. For more information, see Session State.
EnableViewState
Indicates whether view state is maintained across page requests. true if view state is maintained; otherwise, false. The default is true.
EnableViewStateMac
Indicates that ASP.NET should run a machine authentication check (MAC) on the page's view state when the page is posted back from the client. true if view state should be MAC checked; otherwise, false. The default is false.
Note A view-state MAC is an encrypted version of the hidden variable that a page's view state is persisted to when sent to the browser. When you set this attribute to true, the encrypted view state is checked to verify that it has not been tampered with on the client.
ErrorPage
Defines a target URL for redirection if an unhandled page exception occurs.
Explicit
Determines whether the page is compiled using the Visual Basic Option Explicit mode. true indicates that the Visual Basic explicit compile option is enabled and that all variables must be declared using a Dim, Private, Public, or ReDim statement; otherwise, false. The default is false.
Note This attribute is ignored by languages other than Visual Basic .NET. Also, this option is set to true in the Machine.config configuration file. For more information, see Machine Configuration Files.
Inherits
Defines a code-behind class for the page to inherit. This can be any class derived from the Page class. For information about code-behind classes, see Web Forms Code Model.
Language
Specifies the language used when compiling all inline rendering ( and ) and code declaration blocks within the page. Values can represent any .NET-supported language, including Visual Basic, C#, or JScript .NET.
LCID
Defines the locale identifier for the Web Forms page.
Note The locale identifier is a 32-bit value that uniquely defines a locale. ASP.NET uses the default locale of the Web server unless you specify a different locale for a Web Forms page by using this attribute. For more information about locales, search MSDN at http://msdn.microsoft.com.
ResponseEncoding
Indicates the response encoding of page content. Supports values from the Encoding.GetEncoding method.
Src
Specifies the source file name of the code-behind class to dynamically compile when the page is requested. You can choose to include programming logic for your page either in a code-behind class or in a code declaration block in the .aspx file.
Note RAD designers, such as Visual Studio .NET, do not use this attribute. Instead, they precompile code-behind classes and then use the Inherits attribute.
SmartNavigation
Indicates whether the page supports the smart navigation feature of Internet Explorer 5.5 or later..
Note For more information about smart navigation, see the Remarks section.
Strict
Indicates that the page should be compiled using the Visual Basic Option Strict mode. true if Option Strict is enabled; otherwise, false. The default is false.
Note This attribute is ignored by languages other than Visual Basic .NET.
Trace
Indicates whether tracing is enabled. true if tracing is enabled; otherwise, false. The default is false. For more information, see ASP.NET Trace.
TraceMode
Indicates how traces messages are to be displayed for the page when tracing is enabled. Possible values are SortByTime and SortByCategory. The default, when tracing is enabled, is SortByTime. For more information about tracing, see ASP.NET Trace.
Transaction
Indicates whether transactions are supported on the page. Possible values are Disabled, NotSupported, Supported, Required, and RequiresNew. The default is Disabled.
UICulture
Specifies the UI culture setting to use for the page. Supports any valid UI culture value.
ValidateRequest
Indicates whether request validation should occur. If true, request validation checks all input data against a hard-coded list of potentially dangerous values. If a match occurs, an HttpRequestValidationException Class is thrown. The default is true.
This feature is enabled in the machine configuration file (Machine.config). You can disable it in your application configuration file (Web.config) or on the page by setting this attribute to false.

Note This functionality helps reduce the risk of cross-site scripting attacks for straightforward pages and ASP.NET applications. An application that does not properly validate user input can suffer from many types of malformed input attacks, including cross-site scripting and SQL Server injection attacks. There is no substitute for carefully evaluating all forms of input in an application and making sure that they are either properly validated or encoded, or that the application is escaped prior to manipulating data or sending information back to the client. For more information about cross-site scripting, see http://www.cert.org/advisories/CA-2000-02.html.
WarningLevel
Indicates the compiler warning level at which you want the compiler to abort compilation for the page. Possible values are 0 through 4. For more information, see the CompilerParameters.WarningLevel Property property.
Remarks
This directive can be used only in Web Forms pages. You can include only one @ Page directive per .aspx file. To define multiple attributes for the directive, use a space-separated list (do not include a space on either side of the equal sign of a specific attribute, as in trace="true").

Smart navigation is an ASP.NET feature that is supported in Internet Explorer 5.5 and later browsers. It allows a page to be refreshed while maintaining scroll position and element focus between navigations, causing only a single page to be stored in the browser's history, and without the common flicker associated with refreshing a Web page. Smart navigation is best used with ASP.NET pages that require frequent postbacks but with visual content that does not change dramatically on return. Consider this carefully when deciding whether to set this attribute to true.

When the AspCompat attribute is set to true for a page, if you use a constructor to create a COM component before the request is scheduled, it will run on a multithreaded apartment (MTA) thread. Doing this causes significant Web server performance degradation. To avoid this problem, create COM components only from within one of the Page events (such as Page_Load, Page_Init, and so on) or one of the Page methods. Be sure as well that the objects are not created at page construction time. The following examples demonstrate the incorrect and correct way to instantiate a COM object in an AspCompat page. MyComObject is the component, and comObj is the instance of the component.

[C#]Copy Code


Example
The following code instructs the ASP.NET page compiler to use Visual Basic as the inline code language and sets the default HTTP MIME ContentType transmitted to the client to "text/xml".

Desktop Engineer - IT Interview Questions

1) What is Active Directory?
A central component of the Windows platform, Active Directory directory service provides the means to manage the identities and relationships that make up network environments. For example we can create, manage and administrator users, computers and printers in the network from active directory.

2) What is DNS? Why it is used? What is "forward lookup" and "reverse lookup" in DNS? What are A records and mx records?
DNS is domain naming service and is used for resolving names to IP address and IP addresses to names. The computer understands only numbers while we can easily remember names. So to make it easier for us what we do is we assign names to computers and websites. When we use these names (Like yahoo.com) the computer uses DNS to convert to IP address (number) and it executes our request.

Forward lookup: Converting names to IP address is called forward lookup.

Reverse lookup: Resolving IP address to names is called reverse lookup.

'A' record: Its called host record and it has the mapping of a name to IP address. This is the record in DNS with the help of which DNS can find out the IP address of a name.

'MX' Record: its called mail exchanger record. Its the record needed to locate the mail servers in the network. This record is also found in DNS.

3) What id DHCP? Why it is used? What are scopes and super scopes?

DHCP: Dynamic host configuration protocol. Its used to allocate IP addresses to large number of PCs in a network environment. This makes the IP management very easy.

Scope: Scope contains IP address like subnet mask, gateway IP, DNS server IP and exclusion range which a client can use to communicate with the other PCs in the network.

Superscope: When we combine two or more scopes together its called super scope.

4) What are the types of LAN cables used? What is a cross cable?
Types of LAN cables that are in use are "Cat 5" and "Cat 6". "Cat 5" can support 100 Mbps of speed and "CAT 6" can support 1Gbps of speed.

Cross cable: Its used to connect same type of devices without using a switch/hub so that they can communicate.

5) What is the difference between a normal LAN cable and cross cable? What could be the maximum length of the LAN cable?
The way the paired wires are connected to the connector (RJ45) is different
in cross cable and normal LAN cable.
The theoretical length is 100 meters but after 80 meters you may see drop in speed due to loss of signal.

6) What would you use to connect two computers without using switches?
Cross cable.

7) What is IPCONFIG command? Why it is used?
IPCONFIG command is used to display the IP information assigned to a computer. From the output we can find out the IP address, DNS IP address, gateway IP address assigned to that computer.

8) What is APIPA IP address? Or what IP address is assigned to the computer when the DHCP server is not available?
When DHCP server is not available the Windows client computer assigns an automatic IP address to itself so that it can communicate with the network computers. This ip address is called APIPA. ITs in the range of 169.254.X.X.
APIPA stands for Automatic private IP addressing. Its in the range of 169.254.X.X.

9) What is a DOMAIN? What is the difference between a domain and a workgroup?
Domain is created when we install Active Directory. It's a security boundary which is used to manage computers inside the boundary. Domain can be used to centrally administrator computers and we can govern them using common policies called group policies.
We can't do the same with workgroup.

10) Do you know how to configure outlook 2000 and outlook 2003 for a user?
Please visit the link below to find out how to configure outlook 2000 and outlook 2003. http://www.it.cmich.edu/quickguides/qg_outlook2003_server.asp

11) What is a PST file and what is the difference between a PST file and OST file? What file is used by outlook express?
PST file is used to store the mails locally when using outlook 2000 or 2003. OST file is used when we use outlook in cached exchanged mode. Outlook express used odb file.

12) What is BSOD? What do you do when you get blue screen in a computer? How do you troubleshoot it?
BSOD stands for blue screen of Death. when there is a hardware or OS fault due to which the windows OS can run it give a blue screen with a code. Best way to resolve it is to boot the computer is "Last known good configuration".
If this doesn't work than boot the computer in safe mode. If it boots up than the problems with one of the devices or drivers.

13) What is RIS? What is Imaging/ghosting?
RIS stands for remote installation services. You save the installed image on a windows server and then we use RIS to install the configured on in the new hardware. We can use it to deploy both server and client OS. Imaging or ghosting also does the same job of capturing an installed image and then install it on a new hardware when there is a need. We go for RIS or imaging/ghosting because installing OS every time using a CD can be a very time consuming task. So to save that time we can go for RIS/Ghosting/imaging.

14) What is VPN and how to configure it?
VPN stands for Virtual private network. VPN is used to connect to the corporate network to access the resources like mail and files in the LAN. VPN can be configured using the steps mentioned in the KB: http://support.microsoft.com/kb/305550

15) Your computer slowly drops out of network. A reboot of the computer
fixes the problem. What to do to resolve this issue?
Update the network card driver.

16) Your system is infected with Virus? How to recover the data?
Install another system. Install the OS with the lates patches, Antivirus with latest updates. Connect the infected HDD as secondary drive in the system. Once done scan and clean the secondary HDD. Once done copy the files to the new system.

17) How to join a system to the domain? What type of user can add a system to the domain?
Please visit the article below and read "Adding the Workstation to the Domain" http://www.microsoft.com/technet/prodtechnol/windowsserver2003/technologi /directory/

18) What is the difference between a switch and a hub?
Switch sends the traffic to the port to which its meant for. Hub sends the traffic to all the ports.

19) What is a router? Why we use it?
Router is a switch which uses routing protocols to process and send the traffic. It also receives the traffic and sends it across but it uses the routing protocols to do so.

20) What are manageable and non manageable switches?
Switches which can be administered are called manageable switches. For example we can create VLAN for on such switch. On no manageable switches we can't do so.

Cricket 2009 Match Shedule

England Cricket Schedule : Year 2009
Months Versus Matches Fixtures & Result
Jan - March England in West Indies 4 tests + 5 ODI + 1 T20 Eng v WI 2009
May England in Zimbabwe 2 tests + 3 ODIs Canceled
May West Indies in England 2 tests + 3 ODIs Eng v WI 2009
June T20 World cup in England Twenty20 World Cup WC T20 2009
July-August Australia in England Ashes + ODI series Eng v Aus 2009
September Champions Trophy ICC Tournament Champions Trophy
Nov-Dec England in South Africa 4 tests, 5 ODI, 1 T20 Eng v SA 2009

India Cricket Schedule : Year 2009
Jan-Feb India in Pakistan 3 Test + 5 ODI Canceled
March-April India in New Zealand 3 Test + 5 ODI + 2T20 Ind v NZ 2009
June T20 World cup in England Twenty20 World Cup WC T20 2009
July India in West Indies 5 ODI series Ind v WI 2009
September Champions Trophy ICC Tournament Champions Trophy
October Australia in India 7 ODI series Ind v Aus 2009
Nov-Dec Sri Lanka in India 3 Test + 5 ODI Ind v SL 2009

Australia Cricket Schedule : Year 2009
January South Africa in Australia 3 Test + 5 ODI + 2T20 SA in Aus, 09
February New Zealand in Australia 5 ODI + 2T20 NZ in Aus, 09
March-April Australia in South Africa 3 Test + 5 ODI + 2 T20 Aus in SA, 09
June T20 World Cup in England Twenty20 World Cup WC T20 2009
July-August Australia in England 5 Test + 7 ODI + T20 Ashes 2009
September Champions Trophy ICC Tournament Champions Trophy
October Australia in India 7 ODI Series Aus v Ind 2009
November Pakistan in Australia 3 Test + 5 ODI Pak in Aus, 09
December West Indies in Australia 3 Test + 5 ODI WI in Aus, 09

Pakistan Cricket Schedule : Year 2009
January India in Pakistan 3 Test + 5 ODI Canceled
April Pakistan vs Australia in UAE 5 ODI + 1T20 Pak v Aus, in UAE
June T20 World cup in England Twenty20 World Cup WC T20 2009
July-August Pakistan in Sri Lanka 3 Test + 5 ODI Pak in SL, 09
September Champions Trophy ICC Tournament Champions Trophy
November Pakistan in Australia 3 Test + 5 ODI Pak in Aus, 09
December Pakistan vs New Zealand 3 Test + 5 ODI Pak v NZ 2009

New Zealand Cricket Schedule : Year 2009
Jan-Feb New Zealand in Australia 2 Test + 5 ODI NZ in Aus, 09
March India in New Zealand 3 Test + 5 ODI + 2T20 Ind in NZ, 09
June T20 World cup in England Twenty20 World Cup WC T20 2009
August New Zealand in Sri Lanka 2 Test + 3 ODI NZ in SL, 09
September Champions Trophy ICC Tournament Champions Trophy
December Pakistan vs New Zealand 3 Test + 5 ODI Pak vs NZ, 09

Sri Lanka Cricket Schedule : Year 2009
January Sri Lanka in Bangladesh 2 Test + 3 ODI SL in Bng, 09
February India in Sri Lanka 5 ODI series Ind in SL, 09
June T20 World cup in England Twenty20 World Cup WC T20 2009
July Pakistan in Sri Lanka 2 Test + 3 ODI Pak in SL, 09
August New Zealand in Sri Lanka 3 Test + 5 ODI NZ in SL, 09
September Champions Trophy ICC Tournament Champions Trophy
November Sri Lanka in India 3 Test + 5 ODI SL in Ind, 09

South Africa Cricket Schedule : Year 2009
Jan-Feb South Africa in Australia 3 Test + 5 ODI SA in Aus, 09
March Australia in South Africa 3 Test + 5 ODI Aus in SA, 09
June T20 World cup in England Twenty20 World Cup WC T20 2009
September Champions Trophy ICC Tournament Champions Trophy
November England in South Africa 3 Test + 5 ODI Eng in SA, 09

West Indies Cricket Schedule : Year 2009
Jan-Feb England in West Indies 5 Test + 5 ODI Eng in WI, 09
May West Indies in England 2 test + 3 ODI WI in Eng, 09
June T20 World cup in England Twenty20 World Cup WC T20 2009
September Champions Trophy ICC Tournament Champions Trophy
December West Indies in Australia 3 Test + 5 ODI WI in Aus, 09

Bangladesh Cricket Schedule : Year 2009
January Sri Lanka in Bangaldesh 2 test + 3 ODI SL in Bng, 09
June T20 World cup in England Twenty20 World Cup WC T20 2009
September Champions Trophy ICC Tournament Champions Trophy

Thursday, June 11, 2009

Disable Changing Home Page

You can find the gpedit setting in the following location
Go to Start --> Run
Type Gpedit.msc
than go

Administrative Templates
>Windows Component
>>Internet Explorer

Some Interesting Settings

Enable Disable changing home page settings will disable uses changing the home page.


How to disable or enable homepage setting in Internet Explorer

sometimes you might accidently get spyware installed on your computer and it locked your IE homepage to somewhere else. Or may be you will be sharing your computer with your son or kids where they like to modify your homepage setting. You can lock your homepage and make it uneditable. To lock or unlock the homepage, simply follow the steps below:-

- Click Start => Run type regedit and click OK.
- Goto HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Internet Explorer\Control Panel
- Right Click at the empty place of right panel, select New => Dword value
- Name it HomePage
- Double click on the HomePage and enter 1 or 0 (1 = lock homepage, 0 = unlock homepage) as the value

- Next, Go to HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Control Panel
- Right Click at the empty place of right panel, select New => Dword value
- Name it HomePage
- Double click on the HomePage and enter 1 or 0 (1 = lock homepage, 0 = unlock homepage) as the value

Once you finish all the steps above, close all your Internet Explorer and re launch it again. You will see the Home Page will be set according to your setting.

Note: If any of the key (example of key: HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer) do not exists, you need to create them. To create key, just right click on the Parent Key and choose New => Key.

Wednesday, June 10, 2009

Live Match Pakistan vs Sri Lanka

Online Live Cricket Match

Live Cricket England vs South Africa

Watch Online Live Cricket Match

Live Ireland vs New Zealand Online Cricket

Watch Online Cricket Score and Match




Watch live video from Sri Lanka Vs West Indies on Justin.tv



Live Cricket ScoreCard

Live Cricket Score








Disable Pandrive In windows

To disable the access to USB port, in windows XP and 2000:
1. Click Start, and then click Run.
2. In the Open box, type regedit, and then click OK.
3. Locate, and then click the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsbStor­
4. In the right pane, double-click Start.
5. In the Value data box, type 4, click Hexadecimal (if it is not already selected), and then click OK.
6. Quit Registry Editor.
To re-enable a disabled port:
1. Click Start, and then click Run.
2. In the Open box, type regedit, and then click OK.
3. Locate, and then click the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsbStor­
4. In the right pane, double-click Start.
5. In the Value data box, type 3, click Hexadecimal (if it is not already selected), and then click OK.
6. Quit Registry Editor.





Your Ad Here

T20 Final Match Live Online

T20 Final Watch Online



T20 world cup Semifinal Match Online

T20 Semifinal Watch online




Tuesday, June 9, 2009

Watch .India v Ireland Live Online - ICC T20 World Cup

ICC T20 World Cup Twenty20 Live Cricket Streaming Links



Watch Online Live Cricket T20 World cup

New Zealand v South Africa ICC T20 World Cup Live Cricket Streaming links - 10th Match

Watch live video from Sports City on Justin.tv

Netherlands v Pakistan ICC World Cup T20 Live Streaming Twenty20 Cricket

Netherlands v Pakistan ICC World Cup T20 Live Streaming Twenty20 Cricket

Watch live video from Sports City on Justin.tv

Sunday, June 7, 2009

Flash in Asp.net C#

Mail Sending in Asp.net C# Code

MailMessage mm = new MailMessage();
mm.From = new MailAddress("Mail@mail.com");
mm.To.Add("info@mail.com");
mm.Subject =TextBox3.Text + " ("+TextBox6.Text+")";
mm.Body = "Company Name :: "+TextBox1.Text + "
Name ::" + TextBox2.Text + "
Email ::" + TextBox3.Text + "
PhoneNo. ::" + TextBox4.Text + "
Mobile No ::" +
TextBox5.Text + "

" + TextBox7.Text;
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
// smtp.Port =25;
smtp.Host = ConfigurationManager.AppSettings["SMTP"];
smtp.Host = "mail.yellowpagesview.com";
smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["FROMEMAIL"], ConfigurationManager.AppSettings["FROMPWD"]);
smtp.EnableSsl = false;
smtp.Send(mm);
clear();
Label8.Text = "Thank you for contact us!";
//Web.config file setting
configuration>





if you u face any problem in this code Please mail me on ...about problem

Make Home Page Code


  

Add to Favorites   
Make Home Page

Sql Server Tutorial

SQL Server 2005 - Defining Indexes

Using Microsoft SQL Server Constraints

SQL Server Stored Procedures With Example

Friday, June 5, 2009

SQL Server 2005 - Defining Indexes

SQL Server 2005 - Defining Indexes
In this tutorial you will learn about Defining Indexes in SQL Server 2005 - clustered and non clustered indexex, The Query Optimizer, to create an index, To create a unique index, To create a clustered index, To create full-text indexes, To change index properties, To rename an index, to delete an index, To specify a fill factor for an index, To create an XML index and To delete XML Indexes.


When data volumes increase, organizations are faced with problems relating to data retrieval and posting. They feel the need for a mechanism that will increase the speed of data access. An index, like the index of a book, enables the database retrieve and present data to the end user with ease. An index can be defined as a mechanism for providing fast access to table rows and for enforcing constraints.

An index can be created by selecting one or more columns in a table that is being searched. It is a kind of ‘on disk’ structure associated with the table or view and contains keys that are built from one or more of the columns in the table or view. This structure known as B-Tree helps the SQL Server find the row or rows associated with the key values. Indexes can be created on computed columns or xml columns also.

Indexes can be clustered or non clustered. A clustered index stores data rows in the table based on their key values. Each table can have only one clustered index as the key values in the data rows are unique and the index is built on the unique key column. When a table has a clustered index, it is known as a clustered table. Non-Clustered indexes have structures that are different from the data rows. A non clustered index key value is used to point to data rows that contain the key value. This value is known as row locator. The structure of the row locator is determined on the basis of the type of storage of the data pages. If the data page is stored as a heap, a row locator becomes a pointer to a row. If the data page is stored in a clustered table the row locator is a clustered index key. Clustered and Non clustered indexes can be unique and indexes are automatically maintained for a table or view whenever the data table is modified.

SQL Server 2005 permits users add non-key columns to leaf level of the non clustered index for by passing existing index key limits and to execute fully covered index queries.

When the primary key and unique constraints of a table column are defined an automatic index is created.

The Query Optimizer uses indexes to reduce disk I/O operations and use of system resources while querying on data. Queries which contain SELECT, UPDATE or DELETE statements require indexes for optimal performance. When a query is executed, each available method is evaluated for retrieving data and the most efficient one is selected by the Query optimizer. The methodology used may be table scans or index scans. In table scans I/O operations are many and resource intensive as all rows in a table are scanned to find the relevant ones. Index scans are used to search the index key columns to find the storage location of rows needed by the query and as the Index contains very few columns, the query executes faster.

SQL Server 2005 provides the user with a new Transact-SQL DDL statement for modifying relational and XML indexes. The CREATE INDEX statement is enhanced to support XML index syntax, partitioning and the included columns. A number of new index options have been added including the ONLINE option that allows for concurrent user access to underlying data during index operations.

To create an index
1. In Object Explorer, right-click the table for which you want to create an index and click Modify.



2. The table opens in Table Designer.



3. From the Table Designer menu, click Indexes/Keys.



4. In the Indexes/Keys dialog box, click Add.



5. Select the new index in the Selected Primary/Unique Key or Index list and set properties for the index in the grid to the right.



6. Specify any other settings for the index and click Close.

7. The index is created in the database when you save the table.

SQL Server allows users create unique indexes on unique columns such as the identity number of the employee or student or whatever is the unique key by which the component data are identified. A set of columns also can be used to create a unique index. The DBA can set the option of ignoring duplicate keys in a unique index if required. The default is No.

To create a unique index
1. In Object Explorer, right-click the table and click Modify.
2. The table opens in Table Designer.
3. From the Table Designer menu, click Indexes/Keys.
4. Click Add. The Selected Primary/Unique Key or Index list displays the system-assigned name of the new index.


5. In the grid, click Type.



6. Choose Index from the drop-down list to the right of the property.

7. Under Column name, select the columns you want to index. You can select up to 16 columns. For optimal performance, select only one or two columns per index. For each column you select, indicate whether the index arranges values of this column in ascending or descending order.



8. In the grid, click Is Unique.



9. Choose Yes from the drop-down list to the right of the property.

10. Select the Ignore duplicate keys option if you want to ignore new or updated data that would create a duplicate key in the index (with the INSERT or UPDATE statement).



11. The index is created in the database when you save the table or diagram.



Please note that unique indexes cannot be created on a single column if the column contains NULL in more than one row. Similarly indexes cannot be created on multiple columns if the combination of the columns contains NULL in some rows. The NULL values are treated as duplicate values.

Clustered indexes can be created in SQL Server databases. In such cases the logical order of the index key values will be the same as the physical order of rows in the table. A table can have only one clustered index.

To create a clustered index
1. In Object Explorer, right-click the table for which you want to create a clustered index and click Modify.
2. The table opens in Table Designer.
3. From the Table Designer menu, click Indexes/Keys.
4. In the Indexes/Keys dialog box, click Add.
5. Select the new index in the Selected Primary/Unique Key or Index list.
6. In the grid, select Create as Clustered, and choose Yes from the drop-down list to the right of the property.



7. The index is created in the database when you save the table.

A full text index is used when a full text search is required to be performed on all the text based columns of the database. This index relies on a regular index which has to be created before a full text index is created. The regular index is created on a single, non null column. Usually a column with small values is selected for the indexation in a regular index. Often a Catalog is created using an external tool such as SQL Server Management Studio. Textual data from different text file formats are to be stored as image type files before Full text search can be done on the data.

To create full-text indexes
1. In Object Explorer, right-click the table for which you want to create a full-text index and click Modify.
2. The table opens in Table Designer.
3. From the Table Designer menu, click Fulltext Index.


4. The Full-text Index dialog box opens. If the database is not enabled for full text indexing the dialog box will have the add button disabled. To enable full text indexing for the database, right click the database>Click properties and check the Full text indexing check box.



5. Then create a catalog by right clicking on Storage>Full Text Catalog and creating a new Catalog and entering the required information in the dialog box that opens.





6. Now open the Full Text Index property dialog box by clicking on it in the Table Designer menu.



7. Click Add.
8. Select the new index in the Selected Full-text Index list and set properties for the index in the grid to the right.
9. Your index is automatically saved in the database when you save your table in Table Designer. The index is available for modification as soon as you create it.

To change index properties
1. In Object Explorer, right-click the table you want to open and click Modify.
2. From the Table Designer menu, click Indexes/Keys.
3. Select the index from the Selected Primary/Unique Key or Index list.
4. Change properties in the grid.
5. The changes are saved to the database when you save the table.

System defined names are assigned to indexes based on the database file name. If multiple indexes are created on a table the index names are incremented numerically with _1, _2 etc. An index can be renamed to be unique to a table. Since the automatically created index bears the same name as the primary key or unique constraint in a table, another index cannot be renamed later to match the primary key or unique constraint.

To rename an index
1. In Object Explorer, right-click the table with the index you want to rename and click Modify.
2. From the Table Designer menu, click Indexes/Keys.
3. Select the index from the Selected Primary/Unique Key or Index list.
4. In the grid, click Name and type a new name into the text box.



5. The changes are saved to the database when you save the table.

Indexes can be deleted. Usually an index is considered for deletion when the performance of the INSERT,UPDATE and DELETE operations are hindered by the Index.

To delete an index
1. In Object Explorer, right-click the table with indexes you want to delete and click Modify.
2. From the Table Designer menu, click Indexes/Keys.
3. In the Indexes/Keys dialog box, select the index you want to delete.
4. Click Delete.
5. The index is deleted from the database when the table is saved.
6. A similar procedure can be followed for deleting a full text index by selecting Full text index from the Table Designer and selecting the index name and clicking delete button.

Microsoft SQL Server database uses a fill factor to specify how full each index page can be. The percentage of free space allotted to an index is defined as the fill factor. This is an important aspect of indexing as the amount of space to be filled by an index has to be determined by the DBA so that performance is not retarded.

To specify a fill factor for an index
1. In Object Explorer, right-click the table with an index for which you want to specify a fill factor and click Modify.
2. The table opens in Table Designer.
3. From the Table Designer menu, click Indexes/Keys.
4. The Indexes/Keys dialog box opens.
5. Select the index in the Selected Primary/Unique Key or Index list.
6. In the Fill Factor box, type a number from 0 to 100. The value of 100 implies that the index will fill up completely and the storage space required will be minimal. This setting is recommended only for cases where data is unlikely to change. If data is likely to undergo addition and modification, it is better to set a lower value. Storage space required would be in proportion to the value set.



XML indexes cannot be created using the Index/Keys dialog box. One or more XML indexes can be created for xml data type columns on the basis of a primary xml index. Deleting the primary xml index will result in the deletion of all indexes created on the base of the primary index.

To create an XML index
1. In Object Explorer, right-click the table for which you want to create an XML index and click Modify. 2. The table opens in Table Designer.
3. Select the xml column for the index.
4. From the Table Designer menu, click XML Index.



5. In the XML Indexes dialog box, click Add.




6. Select the new index in the Selected XML Index list and set properties for the index in the grid to the right.

To delete XML Indexes
1. In Object Explorer, right-click the table with the XML index you want to delete and click Modify.
2. The table opens in Table Designer.
3. From the Table Designer menu, click XML Index.
4. The XML Index dialog box opens.
5. Click the index you want to delete in the Selected XML Index column.
6. Click Delete.

Using Microsoft SQL Server Constraints

_______________________________________
Introduction
In this article, I want to tell you about SQL Server constraints: what a constraint is, when it is used and for which purposes. You can find in this article some examples of constraint creation and SQL Server 2000 constraints enhancements.
General Concepts
A constraint is a property assigned to a column or the set of columns in a table that prevents certain types of inconsistent data values from being placed in the column(s). Constraints are used to enforce the data integrity. This ensures the accuracy and reliability of the data in the database. The following categories of the data integrity exist:
• Entity Integrity
• Domain Integrity
• Referential integrity
• User-Defined Integrity

Entity Integrity ensures that there are no duplicate rows in a table.
Domain Integrity enforces valid entries for a given column by restricting the type, the format, or the range of possible values.
Referential integrity ensures that rows cannot be deleted, which are used by other records (for example, corresponding data values between tables will be vital).
User-Defined Integrity enforces some specific business rules that do not fall into entity, domain, or referential integrity categories.

Each of these categories of the data integrity can be enforced by the appropriate constraints. Microsoft SQL Server supports the following constraints:
• PRIMARY KEY
• UNIQUE
• FOREIGN KEY
• CHECK
• NOT NULL

A PRIMARY KEY constraint is a unique identifier for a row within a database table. Every table should have a primary key constraint to uniquely identify each row and only one primary key constraint can be created for each table. The primary key constraints are used to enforce entity integrity.

A UNIQUE constraint enforces the uniqueness of the values in a set of columns, so no duplicate values are entered. The unique key constraints are used to enforce entity integrity as the primary key constraints.

A FOREIGN KEY constraint prevents any actions that would destroy link between tables with the corresponding data values. A foreign key in one table points to a primary key in another table. Foreign keys prevent actions that would leave rows with foreign key values when there are no primary keys with that value. The foreign key constraints are used to enforce referential integrity.

A CHECK constraint is used to limit the values that can be placed in a column. The check constraints are used to enforce domain integrity.

A NOT NULL constraint enforces that the column will not accept null values. The not null constraints are used to enforce domain integrity, as the check constraints.

You can create constraints when the table is created, as part of the table definition by using the CREATE TABLE statement.
Examples
The following example creates a check_sale CHECK constraint on an employee table:
CREATE TABLE employee(
EmployeeId INT NOT NULL,
LName VARCHAR(30) NOT NULL,
FName VARCHAR(30) NOT NULL,
Address VARCHAR(100) NOT NULL,
HireDate DATETIME NOT NULL,
Salary MONEY NOT NULL CONSTRAINT check_sale CHECK (salary > 0)
)
You can add constraints to an existing table by using the ALTER TABLE statement. The following example adds a pk_employee primary key constraint on an employee table:
ALTER TABLE employee
ADD CONSTRAINT pk_employee PRIMARY KEY (EmployeeId)
You can add the primary or unique key constraint into an existing table only when there are no duplicate rows in the table. You can drop constraints in an existing table by using the ALTER TABLE statement. The following example drops the pk_employee primary key constraint in the employee table:
ALTER TABLE employee
DROP CONSTRAINT pk_employee
Sometimes you need to perform some actions that require the FOREIGN KEY or CHECK constraints be disabled, for example, your company do not hire foreign employees, you made the appropriate constraint, but the situation was changed and your boss need to hire the foreign employee, but only this one. In this case, you need to disable the constraint by using the ALTER TABLE statement. After these actions will be performed, you can re-enable the FOREIGN KEY and CHECK constraints by using the ALTER TABLE statement.

The following example disables the check_sale constraint in the employee table and enables this constraint later:
-- disable the check_sale constraint in the employee table
ALTER TABLE employee NOCHECK CONSTRAINT check_sale
-- enable the check_sale constraint in the employee table
ALTER TABLE employee CHECK CONSTRAINT check_sale
SQL Server 2000 Constraints Enhancements
SQL Server 2000 introduces many new features. Some of them fall into the constraints area. Now you can control the actions SQL Server 2000 takes when you attempt to update or delete a key to which existing foreign keys point. You can control it by using the new ON DELETE and ON UPDATE clauses in the REFERENCES clause of the CREATE TABLE and ALTER TABLE statements. For example, in the previous versions of SQL Server if you wanted to do a cascade delete from the referenced table when the appropriate record in the parent table is deleted, you had to create a trigger which executed on delete of the parent table, but now you can simply specify the ON DELETE clause in the REFERENCES clause.

The following example is used to create the Books and the Authors tables and create a foreign key constraint which will perform the cascade delete action, therefore, when a row in the Authors table is deleted, the corresponding rows in the Books are also deleted:
CREATE TABLE Books (
BookID INT NOT NULL PRIMARY KEY,
AuthorID INT NOT NULL,
BookName VARCHAR(100) NOT NULL,
Price MONEY NOT NULL
)
GO

CREATE TABLE Authors (
AuthorID INT NOT NULL PRIMARY KEY,
Name VARCHAR(100) NOT NULL
)
GO

ALTER TABLE Books
ADD CONSTRAINT fk_author
FOREIGN KEY (AuthorID)
REFERENCES Authors (AuthorID) ON DELETE CASCADE
GO
Conclusion
Constraints are the built-in mechanism for enforcing data integrity. Using constraints is preferred to using triggers, rules, and defaults because built-in integrity features use much less overhead and perform faster than the ones you can create. When you write your own code to realize the same actions the constraints can make you can make some errors, so the constraints are not only faster, but also are more consistent and reliable. So, you should use triggers and rules only when the constraints do not provide all the needed functionality.

Thursday, June 4, 2009

Basic .NET Framework Questions

What is a IL?

Twist :- What is MSIL or CIL , What is JIT?

(IL)Intermediate Language is also known as MSIL (Microsoft Intermediate Language) or CIL(Common Intermediate Language). All .NET source code is compiled to IL. This IL is thenconverted to machine code at the point where the software is installed, or at run-time by a Just-In-Time (JIT) compiler.

What is a CLR?

Full form of CLR is Common Language Runtime and it forms the heart of the .NET framework.All Languages have runtime and its the responsibility of the runtime to take care of the codeexecution of the program. For example VC++ has MSCRT40.DLL,VB6 has MSVBVM60.DLL,Java has Java Virtual Machine etc. Similarly .NET has CLR. Following are the responsibilities ofCLR

√Garbage Collection :- CLR automatically manages memory thus eliminatingmemory leaks. When objects are not referred GC automatically releases thosememories thus providing efficient memory management.

√Code Access Security :- CAS grants rights to program depending on the securityconfiguration of the machine. Example the program has rights to edit or createa new file but the security configuration of machine does not allow the programto delete a file. CAS will take care that the code runs under the environment ofmachines security configuration.

√Code Verification :- This ensures proper code execution and type safety whilethe code runs. It prevents the source code to perform illegal operation such asaccessing invalid memory locations etc.

√IL( Intermediate language )-to-native translators and optimizer’s :- CLR usesJIT and compiles the IL code to machine code and then executes. CLR alsodetermines depending on platform what is optimized way of running the ILcode.

What is a CTS?


In order that two language communicate smoothly CLR has CTS (Common Type System).Examplein VB you have “Integer” and in C++ you have “long” these datatypes are not compatible so theinterfacing between them is very complicated. In order to able that two different languages can1. Basic .NET 99communicate Microsoft introduced Common Type System. So “Integer” datatype in VB6 and“int” datatype in C++ will convert it to System.int32 which is datatype of CTS. CLS which iscovered in the coming question is subset of CTS.

Note: If you have undergone COM programming period interfacing VB6 application withVC++ application was a real pain as the datatype of both languages did not have acommon ground where they can come and interface, by having CTS interfacing is


What are the different types of Assembly?

There are two types of assembly Private and Public assembly. A private assembly is normally usedby a single application, and is stored in the application's directory, or a sub-directory beneath. Ashared assembly is normally stored in the global assembly cache, which is a repository of assembliesmaintained by the .NET runtime. Shared assemblies are usually libraries of code which manyapplications will find useful, e.g. Crystal report classes which will be used by all application forReports.

What is NameSpace?

Namespace has two basic functionality :-
√NameSpace Logically group types, example System.Web.UI logically groupsour UI related features.
√In Object Oriented world many times its possible that programmers will use thesame class name.By qualifying NameSpace with classname this collision is able tobe removed.

C# Interview Questions

Question: What’s the implicit name of the parameter that gets passed into the class’ set method?
Answer: Value, and its datatype depends on whatever variable we’re changing.

Question: How do you inherit from a class in C#?
Answer Place a colon and then the name of the base class. Notice that it’s double colon in C++.

Question: Does C# support multiple inheritance?
Answer No, use interfaces instead.

Question When you inherit a protected class-level variable, who is it available to?
Answer: Classes in the same namespace.

Question Are private class-level variables inherited?
Answer: Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.

Question Describe the accessibility modifier protected internal.
Answer: It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in).

Question C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?
Answer: Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.

Question What’s the top .NET class that everything is derived from?
Answer: System.Object.

Question How’s method overriding different from overloading?
Answer: When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.

Question What does the keyword virtual mean in the method definition?
Answer: The method can be over-ridden.

Question Can you declare the override method static while the original method is non-static?
Answer: No, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.




Question: What’s the implicit name of the parameter that gets passed into the class’ set method?
Answer: Value, and its datatype depends on whatever variable we’re changing.

Question: How do you inherit from a class in C#?
Answer Place a colon and then the name of the base class. Notice that it’s double colon in C++.

Question: Does C# support multiple inheritance?
Answer No, use interfaces instead.

Question When you inherit a protected class-level variable, who is it available to?
Answer: Classes in the same namespace.

Question Are private class-level variables inherited?
Answer: Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.

Question Describe the accessibility modifier protected internal.
Answer: It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in).

Question C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?
Answer: Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.

Question What’s the top .NET class that everything is derived from?
Answer: System.Object.

Question How’s method overriding different from overloading?
Answer: When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.

Question What does the keyword virtual mean in the method definition?
Answer: The method can be over-ridden.

Question Can you declare the override method static while the original method is non-static?
Answer: No, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.



Question What’s the difference between an interface and abstract class?
Answer: In the interface all methods must be abstract; in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

Question How can you overload a method?
Answer: Different parameter data types, different number of parameters, different order of parameters.

Question If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited constructor to an arbitrary base constructor?
Answer: Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

Question What’s the difference between System.String and System.StringBuilder classes?
Answer: System.String is immutable; System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

Question What’s the advantage of using System.Text.StringBuilder over System.String?
Answer: StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.

Question Can you store multiple data types in System.Array?
Answer: No.

Question What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
Answer: The first one performs a deep copy of the array, the second one is shallow.

Question How can you sort the elements of the array in descending order?
Answer: By calling Sort() and then Reverse() methods.

Question What’s the .NET datatype that allows the retrieval of data by a unique key?
Answer: HashTable.

Question What’s class SortedList underneath?
Answer: A sorted HashTable.

Question Will finally block get executed if the exception had not occurred?
Answer: Yes.



Question What’s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception?
Answer: A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.

Question Can multiple catch blocks be executed?
Answer: No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.

Question Why is it a bad idea to throw your own exceptions?
Answer: Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.

Question What’s a delegate?
Answer: A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.

Question What’s a multicast delegate?
Answer: It’s a delegate that points to and eventually fires off several methods.

Question How’s the DLL Hell problem solved in .NET?
Answer: Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.

Question What are the ways to deploy an assembly?
Answer: An MSI installer, a CAB archive, and XCOPY command.



Question What’s a satellite assembly?
Answer: When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

Question What namespaces are necessary to create a localized application?
Answer: System.Globalization, System.Resources.

Question What’s the difference between // comments, /* */ comments and /// comments?
Answer: Single-line, multi-line and XML documentation comments.

Question How do you generate documentation from the C# file commented properly with a command-line compiler?
Answer: Compile it with a /doc switch.
Question What’s the difference between and XML documentation tag?
Answer: Single line code example and multiple-line code example.

Question Is XML case-sensitive?
Answer: Yes, so and are different elements.

Question What debugging tools come with the .NET SDK?
Answer: CorDBG – command-line debugger, and DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch.

Question What does the This window show in the debugger?
Answer: It points to the object that’s pointed to by this reference. Object’s instance data is shown.

Question What does assert() do?
Answer: In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.

Question What’s the difference between the Debug class and Trace class?
Answer: Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.

Question Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
Answer: The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.

Question Where is the output of TextWriterTraceListener redirected? To the Console or a text file depending on the parameter passed to the constructor.

Question How do you debug an ASP.NET Web application?

Answer: Attach the aspnet_wp.exe process to the DbgClr debugger.

Question What are three test cases you should go through in unit testing?
Answer: Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).



Question Can you change the value of a variable while debugging a C# application?
Answer: Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.

Question Explain the three services model (three-tier application). Presentation (UI), business (logic and underlying code) and data (from storage or other sources).

Question What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?

Answer: SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it’s a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.
Question What’s the role of the DataReader class in ADO.NET connections?
Answer: It returns a read-only dataset from the data source when the command is executed.

Question What is the wildcard character in SQL?
Answer: Let’s say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’.

Question Explain ACID rule of thumb for transactions. Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t), Isolated (no transaction sees the intermediate results of the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after).

Question What connections does Microsoft SQL Server support?

Answer: Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).

Question Which one is trusted and which one is untrusted?
Answer: Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.

Question Why would you use untrusted verificaion?
Answer: Web Services might use it, as well as non-Windows applications.

Question What does the parameter Initial Catalog define inside Connection String? The database name to connect to.

Question What’s the data provider name to connect to Access database?
Answer: Microsoft.Access.

Question What does Dispose method do with the connection object?
Answer: Deletes it from the memory.

Question What is a pre-requisite for connection pooling?
Answer: Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.




1.Does C# support multiple-inheritance?
No. But you can use Interfaces.

2.Where is a protected class-level variable available?
It is available to any sub-class derived from base class

3.Are private class-level variables inherited?
Yes, but they are not accessible.


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

6.Which class is at the top of .NET class hierarchy?
System.Object.

7.What does the term immutable mean?
The data value may not be changed.
Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.

8.What’s the difference between System.String and System.Text.StringBuilder classes?
System.String is immutable.
System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

9.What’s the advantage of using System.Text.StringBuilder over System.String?

StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.

10.Can you store multiple data types in System.Array?
No.

11.What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.

12.How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.

13.What’s the .NET collection class that allows an element to be accessed using a unique key?
HashTable.

14.What class is underneath the SortedList class?
A sorted HashTable.

15.Will the finally block get executed if an exception has not occurred?
Yes.

16.What’s the C# syntax to catch any possible exception?
A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.

17.Can multiple catch blocks be executed for a single try statement?
No. Once the proper catch block processed, control is transferred to the finally block .

18.Explain the three services model commonly know as a three-tier application?
Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources).

Class Questions

1.What is the syntax to inherit from a class in C#?
Place a colon and then the name of the base class.
Example: class MyNewClass : MyBaseClass

2.Can you prevent your class from being inherited by another class?
Yes. The keyword “sealed” will prevent the class from being inherited.

3.Can you allow a class to be inherited, but prevent the method from being over-ridden?
Yes. Just leave the class public and make the method sealed.

4.What’s an abstract class?
A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.

5.When do you absolutely have to declare a class as abstract?

1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.

2. When at least one of the methods in the class is abstract.


6.What is an interface class?
Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes.

7.Why can’t you specify the accessibility modifier for methods inside the interface?
They all must be public, and are therefore public by default.

8.Can you inherit multiple interfaces?
Yes. .NET does support multiple interfaces.

9.What happens if you inherit multiple interfaces and they have conflicting method names?
It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.

10. What’s the difference between an interface and abstract class?
In an interface class, all methods are abstract - there is no implementation. In an abstract class some methods can be concrete. In an interface class, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers.

11. What is the difference between a Struct and a Class?
Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval. Another difference is that structs cannot inherit.

Method and Property Questions

1. What’s the implicit name of the parameter that gets passed into the set method/property of a class?
Value. The data type of the value parameter is defined by whatever data type the property is declared .

2. What does the keyword “virtual” declare for a method or property?
The method or property can be overridden.

3. How is method overriding different from method overloading?
When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same name within the class.

4. Can you declare an override method to be static if the original method is not static?
No. The signature of the virtual method must remain the same. (Note: Only the keyword virtual is changed to keyword override)

5. What are the different ways a method can be overloaded?
Different parameter data types, different number of parameters, different order of parameters.

6. If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?
Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

Events and Delegates

1. What’s a delegate?
A delegate object encapsulates a reference to a method.

2. What’s a multicast delegate?
A delegate that has multiple handlers assigned to it. Each assigned handler (method) is called.

3. What’s the implicit name of the parameter that gets passed into the class’ set method?
Value, and it’s datatype depends on whatever variable we’re changing.

4. How do you inherit from a class in C#?
Place a colon and then the name of the base class.

5. Does C# support multiple inheritance?
No, use interfaces instead.

6. When you inherit a protected class-level variable, who is it available to?
Classes in the same namespace.

7. Are private class-level variables inherited?
Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited.

8. Describe the accessibility modifier protected internal.?
It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in).

9. C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?
Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.

10. What’s the top .NET class that everything is derived from?
System.Object.

11. How’s method overriding different from overloading?
When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.

12. What does the keyword virtual mean in the method definition?
The method can be over-ridden.

13. Can you declare the override method static while the original method is non-static?
No, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.

14. Can you override private virtual methods?
No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access.

15. Can you prevent your class from being inherited and becoming a base class for some other classes?
Yes, that’s what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName.
It’s the same concept as final class in Java.

16. Can you allow class to be inherited, but prevent the method from being over-ridden?
Yes, just leave the class public and make the method sealed.

17. What’s an abstract class?
A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden.
Essentially, it’s a blueprint for a class without any implementation.

18. When do you absolutely have to declare a class as abstract (as opposed to free-willed educated choice or decision based on UML diagram)?
When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden.

19. What’s an interface class?
It’s an abstract class with public abstract methods all of which must be implemented in the inherited classes.

20. Why can’t you specify the accessibility modifier for methods inside the interface?
They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it’s public by default.

21. Can you inherit multiple interfaces?
Yes, why not.

22. And if they have conflicting method names?
It’s up to you to implement the method inside your own class, so implementation is left entirely up to you.
This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.

23. What’s the difference between an interface and abstract class?
In the interface all methods must be abstract, in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

24. How can you overload a method?
Different parameter data types, different number of parameters, different order of parameters.

25. If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited constructor to an arbitrary base constructor?
Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

26. What’s the difference between System.String and System.StringBuilder classes?
System.String is immutable, System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

27. Is it namespace class or class namespace?
The .NET class library is organized into namespaces. Each namespace contains a functionally related group of classes so natural namespace comes first.

SQL Server Stored Procedures With Example

Learning something new is challenging. Learning something new on your own redefines challenging.
Chances are, you are reading my article because you want to learn how to write stored procedures. You are new to this, and you don't know where to start. You are exactly where I was when I wanted to learn how to write stored procedures. The purpose of this article is to help the developer who doesn't know where to start. I will give you a place to start, teach you techniques beyond the basic "hello world", and walk you through examples. I learned how to write stored procedures alone, and have decided to let you use my experiences to your advantage. This article will consist of the following topics:
1. What are stored procedures?


2. What do you need to get started?


3. Writing your first stored procedure


4. Writing more sophisticated stored procedures


a. Input Variables


b. Input Variables with SELECT and UPDATE Statements


c. Exercise: Pass Data to a SELECT Stored Procedure


5. Conclusion


6. Database script for SPFORBEGINNERS (the database referenced in this article)
At the end, I have also included a SQL script for creating the database used in my examples. It is a small database, and easily replicated. Of course, I am interested in receiving any feedback at tomoneill@deloitte.com.

What Are Stored Procedures?
Have you ever written SQL statements, like inserts, selects, and updates? Then you have already written most of a stored procedure. A stored procedure is an already written SQL statement that is saved in the database. If you find yourself using the same query over and over again, it would make sense to put it into a stored procedure. When you put this SQL statement in a stored procedure, you can then run the stored procedure from the database's command environment (I am a SQL Server kind of guy, and run stored procedures from the Query Analyzer), using the exec command.
An example is:
exec usp_displayallusers
The name of the stored procedure is "usp_displayallusers", and "exec" tells SQL Server to execute the code in the stored procedure. (Note: "usp_" in front of the stored procedure name is used to designate this stored procedure as a user-created stored procedure.) The code inside the stored procedure can be something as simple as:
SELECT * FROM USERLIST
This "select" statement will return all data in the USERLIST table. You may think, skeptically, that stored procedures aren’t terribly useful. Just save the query and run it when you need to. Too easy, right?
Well, there is more to the story. Many queries get more complex than "select * from . . ." Also, you may want to call the stored procedure from an application, such as an ASP page, Visual Basic application, or a Java servlet. With a stored procedure, you can store all the logic in the database, and use a simple command to call the stored procedure. Later, if you decide to migrate from ASP to J2EE, you only need to change the application layer, which will be significantly easier. Much of the business logic will remain in the database.
Enough background—let’s write some stored procedures.

Getting Started with Stored Procedures
What do I need to get started? I have heard that question often. To begin writing stored procedures, the following are essential:
1. A database management system.


2. A database built inside the database management system (see the end of this article for a sample).


3. A text editor, such as Notepad or Query Analyzer.
Items 1 and 2 are absolutely essential. You can’t write stored procedures without a database. They would be useless. Sometimes, I write my procedures in Notepad (or another text editor), and copy them into the New Stored Procedure window in SQL Server. The New Stored Procedure window is a bit small, and in Notepad I can spread things out a bit (you’ll see later).
Next, you will have to decide what you want your stored procedure to do. It can be tempting to just dive right into the task at hand, but it is always prudent to sketch out some ideas first. Some considerations should be:
• Do you want to view data in the database (SELECT), insert new records (INSERT INTO), or do I want to change an existing record (UPDATE)?


• With which tables will you have to work? Does it make sense to create a VIEW first?


• How often will this procedure actually be used?
Once you have struggled with these questions (something of an exaggeration, I guess), you will be ready to start coding!
Note: Throughout this article, I will focus on stored procedures for SQL Server. You can apply the same principles to other database management systems, but I will make clear references to working in a SQL Server environment.
Page 2 / 8
Writing Your First Stored Procedure
Finally!!! It is time to write your first stored procedure (assuming you have created your database). In SQL Server, under your database tree, select the "Stored Procedures" option from Enterprise Manager (when you gain more experience, you can use Query Analyzer to create stored procedures). There will be a number of system generated stored procedures there already. Just ignore them. Your next step is to right click on any of the existing stored procedures (don’t worry, you won’t actually use them), then select "New Stored Procedure . . ." This will open the stored properties window I discussed above. The following code will appear already in the window:
CREATE PROCEDURE [PROCEDURE NAME] AS
The first thing I usually do is provide some spacing (we’ll need it later). This isn’t required, and as you write more stored procedures, you will find a style with which you are comfortable.

/*
We will use this area for comments
*/
CREATE PROCEDURE [PROCEDURE NAME]
/*
We will put the variables in here, later
*/
AS
/*
This is where the actual SQL statements will go
*/

So far, it is pretty simple. Let’s look at the top comments section first,

/*
We will use this area for comments
*/

When you write stored procedures (especially for a business or academic project), you never know who will eventually have to alter the code. This top section is useful for comments about the stored procedure, a change log, and other pertinent information. While this is not required, it is just a good programming habit. For this exercise, make it look like this:

/*
Name: usp_displayallusers
Description: displays all records and columns in USERLIST table
Author: Tom O’Neill
Modification Log: Change
Description Date Changed By
Created procedure 7/15/2003 Tom O’Neill
*/

Of course, you can use your own name and today’s date.
The next section will change only slightly. Every stored procedure needs the words "CREATE PROCEDURE" followed by the name you want to assign to the stored procedure. While not required, stored procedure names usually begin with the prefix "usp_".

CREATE PROCEDURE usp_displayallusers

This tells the database that you are creating a stored procedure named "usp_displayallusers". So far, your stored procedure should look like this:

/*
Name: usp_displayallusers
Description: displays all records and columns in USERLIST table
Author: Tom O’Neill
Modification Log: Change
Description Date Changed By
Created procedure 7/15/2003 Tom O’Neill
*/
CREATE PROCEDURE usp_displayallusers

The next step is to think about variables. Since this is our first stored procedure together, we won’t deal with them yet. Just keep in mind that they are usually added after the "CREATE PROCEDURE" line. Since we don’t have variables, the next step is quite simple. Put the word "AS" beneath the create procedure line.

CREATE PROCEDURE usp_displayallusers
AS

Page 3 / 8
We are telling the database that we want to create a stored procedure that is called "usp_displayallusers" that is characterized by the code that follows. After the "AS" entry, you will simply enter SQL code as you would in a regularly query. For our first, we will use a SELECT statement:

SELECT * FROM USERLIST

Now, your stored procedure should look like this:
/*
Name: usp_displayallusers
Description: displays all records and columns in USERLIST table
Author: Tom O’Neill
Modification Log: Change
Description Date Changed By
Created procedure 7/15/2003 Tom O’Neill
*/
CREATE PROCEDURE usp_displayallusers
AS
SELECT * FROM USERLIST

Congratulations, you have written your first stored procedure. If you authored the procedure in a text editor, now would be a good time to copy it into the New Stored Procedure window in SQL Server. Once you have done so, click the "Check Syntax" box. This is a great troubleshooting tool for beginners and experts alike. When SQL Server tells you "Syntax check successful!", you can click OK to save your stored procedure. To view the procedure, simply double-click usp_displayallusers in the Stored Procedures window. To run your stored procedure, open the Query Analyzer and type:

exec usp_displayallusers

Then, click the green "play" button to run the query. You will see that the procedure has run successfully.
It can be frustrating to start from scratch. Right now, you can think of all the things you want to accomplish with stored procedures; you just need to learn how! That will happen next. Let’s take a look at some more useful stored procedures.

More Sophisticated Stored Procedures
In this section, we are going to address a few new topics. In addition to writing SELECT queries, you are going to want to insert, update, and delete database records. Also, you will probably want to pass information from outside the query. Since inserts and updates require some sort of data input to be useful, our first topic will be variables. From there, we will use data stored in variables for inserts and updates.
Note: In this article, we will only address input variables (variables that pass data to the SQL statement in the stored procedure). There are various types of outputs and returns, and they can become quite complex. Since this article is an introduction, we will leave outputs for another time.

Input Variables
There are many reasons for wanting to pass data to a stored procedure, especially if your stored procedure is being called by a dynamic web page or other application. You may want to use a SELECT statement to pull information into the application for dynamic display. In this case, you would pass selection criteria to the stored procedure (for use in a WHERE clause). If you are inserting new records, you will need to get the data from somewhere. Updating existing records also involves simply getting the data. In both INSERT and UPDATE statements, it is necessary to pass data to the stored procedure. For INSERT, UPDATE, and SELECT statements (to name a few), you can pass the data to your stored procedure using variables.
Input variables are essentially "storage" for data that you want to pass to your stored procedure. Inside your stored procedure, you will declare variables at the top of the stored procedure. How does the data get there? The data is entered in the exec statement that you use to kick off the stored procedure. We’ll discuss that in more detail in a bit.
There are two types of variables that you can create in SQL Server stored procedures: Global and Local. Since this is for beginners, I don’t want to go crazy with too many options. We’ll stick to local variables for now. You can name a variable most anything you want, though it is best to stick with meaningful works and abbreviations. I also tend to avoid punctuation, though underscores ("_") are sometimes helpful. The only real requirement is that you begin your variable with the "@" symbol. Here are some examples:
• @f_name


• @fullname


• @HomePhone


• @ext
For every data element you want to pass, you will need to declare a variable. Declaring a variable is quite easy. You decide on a name and a datatype (integer, text, etc.), and indicate the name and datatype at the top of the procedure (below the "CREATE PROCEDURE" line). Let’s add a record to USERLIST. Remember the following:
• "usr_id" is the primary key, and is system-generated. We won’t need to pass a value for it.


• "login", "pswd", "l_name", and "email" are required fields. We will have to pass values for them.

Page 4 / 8
First, let’s create the header information (like the author, change log, etc.) that should be a part of every stored procedure.

/*
Name: usp_adduser
Description: Adds a user
Author: Tom O’Neill
Modification Log: Change
Description Date Changed By
Created procedure 7/15/2003 Tom O’Neill
*/

Remember this?

CREATE PROCEDURE usp_adduser
/*
We will put the variables in here, later
*/

Add the "CREATE PROCEDURE" line, assigning the name "usp_adduser". Our next step is to remove the comments and declare our variables!
To start, let’s look at how our variables will fit. We will need to create a variable for every value we may need to pass. We may not pass a value to every field every time we run the stored procedure. But, we do need to address the possibility that over the life of the stored procedure, every data element may be used. The best way to address this issue is to create a variable for every column in USERLIST. To keep this example simple, we are also assuming that each of the columns can be NULL, and we will also be passing all of the variables to the stored procedure. If some of the columns cannot be NULL, or if not all of the columns will be affected, then the stored procedure and/or the exec statement have to be rewritten slightly. The list below shows the variable and the field with which it is associated.
• @login—login


• @pswd—pswd


• @f_name—f_name


• @l_name—l_name


• @address_1—address_1


• @address_2—address_2


• @city—city


• @state—state


• @zipcode—zipcode


• @email—email

You have probably noticed that I gave the variables names that closely resemble the column names with which they are associated. This will make it easier for you to maintain the stored procedure in the future. Delete the comments about variables, and put your list of variables beneath the "CREATE PROCEDURE" line.

CREATE PROCEDURE usp_adduser

@login
@pswd
@f_name
@l_name
@address_1
@address_2
@city
@state
@zipcode
@email

Next, add datatypes to each of the variables. The datatype assigned to the variable should match the datatype assigned to the corresponding column in the database. For any elements with the "char", "varchar", or "numeric" datatypes, you will need to put the maximum character length list in parentheses after the datatype. Separate all variables (except the last one), with a comma.

CREATE PROCEDURE usp_adduser
@login varchar(20),
@pswd varchar(20),
@f_name varchar(25),
@l_name varchar(35),
@address_1 varchar(30),
@address_2 varchar(30),
@city varchar(30),
@state char(2),
@zipcode char(10),
@email varchar(50)

With that last keystroke, you have created your first set of variables. To finish "usp_adduser", we will have to figure out what we want the stored procedure to do, then add the appropriate code after the "AS" statement. This stored procedure will add a new record to the USERLIST table, so we should use an INSERT statement. The SQL should be:

INSERT INTO USERLIST (login, pswd, f_name, l_name, address_1, address_2, city, state, zipcode, email)

The INSERT clause is pretty standard. The VALUES clause is a bit more complex. If you have worked with databases, you are probably accustomed to seeing something like this:

VALUES ('dnelson', 'dean2003', 'Dean', 'Nelson', '200 Berkeley Street', '', 'Boston', 'MA', '02116', 'dnelson@test.com')

Since we are passing values from variables, it will look a bit different. Instead of putting the actual values in the VALUES clause, we’ll just put the variables. You won’t need to use quotes.

VALUES (@login, @pswd, @f_name, @l_name, @address_1, @address_2, @city, @state, @zipcode, @email)

What does the entire stored procedure look like? Let’s pull it all together.

/*
Name: usp_adduser
Description: Add new logins.
Author: Tom O’Neill
Modification Log: Change
Description Date Changed By
Created procedure 7/15/2003 Tom O’Neill
*/

CREATE PROCEDURE usp_adduser
@login varchar(20),
@pswd varchar(20),
@f_name varchar(25),
@l_name varchar(35),
@address_1 varchar(30),
@address_2 varchar(30),
@city varchar(30),
@state char(2),
@zipcode char(10),
@email varchar(50)
AS
INSERT INTO USERLIST (login, pswd, f_name, l_name, address_1, address_2, city, state, zipcode, email)
VALUES (@login, @pswd, @f_name, @l_name, @address_1, @address_2, @city, @state, @zipcode, @email)

It looks pretty long and complex, though we know from the process above that the stored procedure is not necessarily complex; it just contains a lot of data. If you have been working in a separate text editor, copy your stored procedure into the New Stored Procedure window in SQL Server, and check the syntax. The result should be a successful syntax check.
Now, we have a stored procedure that can accept external data. What do we do with it? How do we get the data? It’s not that hard; I promise. We’ll start with the "exec" statement we used when we wrote our first stored procedure. Remember?

exec usp_displayallusers

We have a new stored procedure to execute, so this time, the command will be:

exec usp_adduser

There is still the issue of how to get our data into the stored procedure. Otherwise, all those variables will be useless. To get data into our stored procedure, simply add the information (in single quotes ' ') after the execute statement.

exec usp_adduser ' '

Remember to pass as many parameters as you have variables, otherwise SQL Server will throw an error. Since we have ten variables, your execute statement should look like this:

exec usp_adduser ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '

Next, let’s include the data that we will want to pass to usp_adduser. Your execute statement will look like:

exec usp_adduser 'dnelson', 'dean2003', 'Dean', 'Nelson', '200 Berkeley Street', ' ', 'Boston', 'MA', '02116', 'dnelson@test.com'

Running the query should be successful, and SQL Server will tell you that one row has been affected. Now, let’s try using input variables with some other query types.

Input Variables with SELECT and UPDATE Statements
Regardless of the type of SQL statement you use, variables work the same way. Look at the following stored procedure:

/*
Name: usp_updateuser
Description: Updates user information
Author: Tom O’Neill
Modification Log: Change
Description Date Changed By
Created procedure 7/15/2003 Tom O’Neill
*/


CREATE PROCEDURE usp_updateuser
@usr_id int,
@login varchar(20),
@pswd varchar(20),
@f_name varchar(25),
@l_name varchar(35),
@address_1 varchar(30),
@address_2 varchar(30),
@city varchar(30),
@state char(2),
@zipcode char(10),
@email varchar(50)
AS
UPDATE USERLIST
SET
login=@login,
pswd=@pswd,
f_name=@f_name,
l_name=@l_name,
address_1=@address_1,
address_2=@address_2,
city=@city,
state=@state,
zipcode=@zipcode,
email=@email
WHERE usr_id=@usr_id

What’s different about this stored procedure (compared to the INSERT stored procedure)? Aside from the obvious fact that this is an UPDATE instead of an INSERT? First, you should have noticed that we added another variable, @usr_id. This new variable has the datatype "int" because it is an integer field. Why did we have to do this? In the INSERT stored procedure, we were creating a new record. Since usr_id is assigned by the system, we didn’t need to worry about it. Now we are updating an existing record. To ensure that we update the right record, we need to use the primary key as a filter. Notice that @usr_id shows up again in the WHERE clause, where we would normally have a value in quotes (like '1233').
The other difference is that we have included the variables in the SET clause. Instead of:

login='dnelson'

we have used:

login=@login

Remember, when you use variables, you do not have to use quotes.
The remaining SQL statement to address in this section is the SELECT statement. We can pass data to a SELECT statement using variables as well. I’ll let you do this one yourself.

Page 7 / 8
Exercise: Pass Data to a SELECT Stored Procedure
Create a stored procedure that returns one record, based on the table’s primary key. Remember to:
1. Create the header record (commented)


2. Create the stored procedure name and declare variables


3. Create the rest of your stored procedure
When you are done, copy your stored procedure into the SQL Server New Stored Procedure window (if you are using a separate text editor), and check the syntax. Also, you may want to open the Query Analyzer and run the execute statement. I’ll provide both the stored procedure and execute statement (with sample data) below.

Answers
Stored Procedure:
/*
Name: usp_finduser
Description: find a user
Author: Tom O’Neill
Modification Log: Change
Description Date Changed By
Created procedure 7/15/2003 Tom O’Neill
*/

CREATE PROCEDURE usp_finduser
@usr_id int
AS
SELECT * FROM USERLIST
WHERE usr_id=@usr_id

Execute Statement:
exec usp_finduser '1'

Did it work? If not, keep trying! You’ll get there.