Professional Documents
Culture Documents
...
...
if (intAddressid==0)
489
{
objCommand.CommandText = "insert intoAddress(Name, Address, Phonenumber)
values('" + strName+ "','" + strAddressName+ "','" + strPhoneNumber + "')" ;
}
else
{objCommand.CommandText = "updateAddress set name='" + strName+ "',
Address='" + strAddressName+ "',phonenumber='" + strPhoneNumber + "' where
addressid=" + intAddressid.ToString();}
...
Objcommand.executenonquery();}
490
Business Layer
Figure 15.22: - Business object diagram
Above is the business object diagram for the address application. There are two main
business objects:-
AddressBook
This class will have the validations and two basic operational functionalities adding new
addresses and delete addresses. AddressBook class represents a single entity class.
491
All the business validations will be written in the set property of the class. For instance
for the name property you can see that if there is no name provided it will throw error to
the client.
PublicstringName
{Set
{
/ / if thestrNameis not provided then throwa exception
If value.length == 0
{
Thrownewexception(Nameis a compulsory field);
}
/ / if all thevalidations areok then set theprivatevalue
strName= value;}
Get
{return strName;}}
Same type of business validation will follow for address property.
addAddress()
This method will call the addAddress method of the database class addressBookDB
and add new address record in the database.
Pseudo-code for calling the database object will be something as given below.
addressBookDB.addAddress (intAddressid, strName, strAddress, strPhoneNumber)
Also note that the private variables passed to the address database objects.
492
deleteAddress()
This method will call the deleteAddress method of the addressBookDB class and
delete a particular address from the address database.
Pseudo-code for calling the database object will be something as below.
addressBookDB.deleteAddress(intAddressid);
AddressBooks ( inherits from Collectionbase)
This class will be having collection of AddressBook type objects and it inherits from
the System.collections. Collectionbase class. AddressBooks represents a collection. It
has the following methods and properties:-
LoadAddress
Loadaddress method loads the address in to collection base. Below is the pseudo-code
for the same.
publicvoid loadAddress()
{
/ / beforeweload all theaddress clear thelist collection
List.Clear();
/ / call theaddressbookdb and and theget theaddress datareader
objDatareader = objaddressBookDB.GetAddresses();
/ / loop through thedatareader and load the
/ / collection of addressbooks
while(objDatareader.Read())
{
AddressBook objAddressBook ;
objAddressBook = newAddressBook();
objAddressBook.addressId = objDatareader["Addressid"];
493
objAddressBook.Address = objDatareader["Address"].ToString();
objAddressBook.Name= objDatareader["Name"].ToString();
objAddressBook.PhoneNumber = objDatareader["PhoneNumber"].ToString();
/ / after thevalues areset add it tothelist collection
List.Add(objAddressBook);
}
/ / finally closetheobject
objDatareader.Close();
}
LoadAddress(int intAddressid)
This is a overloaded method it will have the same logic as defined previously for
loadAddress method without parameters. Only that it will call
objaddressBookDB.GetAddresses(intAddressid);
494
Presentation Layer
FrmAddressBook.cs
Figure 15.23 : - UI component Diagram
495
Presentation layer define the way addressbook and addressbooks object will flow
and interact.
Following are the various methods and properties in the presentation layer:-
AddressBook and AddressBooks object will define a private variable in the presentation
layer.
privateAddressBook objAddressBook = newAddressBook();
privateAddressBooks objAddressBooks = newAddressBooks();
GUI components
Figure 15.24 :- GUI Component list
setValueFromUI
This will take the value from the UI components and set it to the address object. Pseudo-
code is as shown below:-
privatevoid setValueFromUI()
{
objAddressBook.Name= txtName.Text;
496
objAddressBook.PhoneNumber = txtPhoneNumber.Text;
objAddressBook.Address = txtAddress.Text;
}
ClearUI
This sub routine clears all the user interface values.
privatevoid clearUI()
{
txtName.Text = "";
txtPhoneNumber.Text = "";
txtAddress.Text = "";
}
LoadAddress
This subroutine will bind the address collection object that is objAddressBooks to the
datagrid.
privatevoid loadAddress()
{/ / call theload method of theaddressbooks object
objAddressBooks.loadAddress();
/ / clear all theprevious records in thegrid
dgAddresses.DataSource= null;
/ / rebind thefresh newdata in t headdressbooks collection
dgAddresses.DataSource= objAddressBooks;
/ / refresh thegrid
dgAddresses.refresh();
}
497
LoadAddressinUI
LoadAddressinUI does the exact opposite of what SetValueFromUI does.
publicvoid loadAddressinUI(int intAddressId)
{
/ / Load theaddressbooks object with theaddressid
objAddressBooks.loadAddress(intAddressId);
/ / check if thereareany address object loaded
if (objAddressBooks.Count > 0)
{
/ / if yes then set thecurrent addressbook object tothefirst object of the
/ / addressbooks collection object
objAddressBook = objAddressBooks[0];
}
/ / finally load all theobject valuein totheaddress book UI
txtName.Text = objAddressBook.Name;
txtAddress.Text = objAddressBook.Address;
txtPhoneNumber.Text = objAddressBook.PhoneNumber;}
498
Method call flow for address book
Figure 15.25 : - Method flow in UI
Above shows how the methods will interact among themselves to accomplish the task.
499
Test plans
Add new Address with Name as nothing
Steps for the test:
Start the Address book application
Enter the following data
Press Update button
System should pop up with error message Name is Compulsory field
Enter proper Name data.
Press update button
System should save the information and display the newly entered data in the grid
below.
Add new Address with Address as nothing
Steps for the test:
Start the Address book application
Enter the following data
Press Update button
500
System should pop up with error message Address is Compulsory field
Enter proper Name data.
Press update button
System should save the information and display the newly entered data in the grid
below.
Update Address
Steps for the test:
Start the Address book application
Select one of the addresses from the address data grid. Address details will be
displayed on the textboxes above.
Change some information in all the three fields.
Press Update button
System should save the changed information and display the newly entered data in
the grid below.
Cancel Address
Steps for the test:
Start the Address book application
Enter the following data
Press Cancel button
501
System should clear all the three textboxes.
Delete existing Address data
Steps for the test:
Start the Address book application
Select one of the addresses from the address data grid. Address details will be
displayed on the textboxes above.
Press Delete button
System should delete the selected address and grid below is refreshed and the currently
deleted address is not displayed in the grid.
Source code
You can get the source code from the CD. I have tried to comment as much as possible
but if you do not get some logic mail me at shiv_koirala@yahoo.com. Below are the
snapshot of all the documents which are provided in the CD. As this is a sample project
the documents are small in size and not that complicated. But when it comes to huge
projects there are more documents than what I have created. But these are the basic
documents which you should have.
502
Figure 15.26 :- Requirement Gathering Document Snapshot.
Figure 15.27 : - Technical Specification Document Snapshot
503
Figure 15.28 : - Test case document snapshot
When you run the application you can get the following error. This happens because the
connection string is not pointing to proper path where MDB file exists.
Figure 15.29 : - Error while running address book application
504
So click on the config file WindowsAddressBook.exe.config which is present in the
Debug folder and open the same in notepad.
Figure 15.30 : - Edit WindowsAddressBook.exe.config
After you edit the config file in notepad change the Datasource property in
ConnectionString to the path where the database file .MDB is located.
505
16. Test Yourself
Q1. Crushader company wants to revamp his website. One of the important changes
Crushader want is to display Ad banners. As a developer you want to initialize the
banner image paths when the first user accesses the application. So what will you do?
1. Add code in application_onstart event of global.asax file.
2. Add code in application_begin request event of global.asax file.
3. Add code to session_onstart event of global.asax.
4. Add code in page.load event handler in the startup page of the application.
5. Create a user control named Banner.ascx and initialize all the image paths in this
ascx. Then include this banner.ascx in all the pages of the application which needs the
banner displays.
Answer 1.
Q2 Which one of the following is a limitation of XML serialization?
A. In classes that implement IEnumerable, the collection is not serialized.
B. You cannot serialize an object's public fields.
C. You cannot serialize DataSet objects.
D. You cannot serialize XmlNode object.
E. It does not serialize type information.
Answer E
XML serialization does not include type information. For example, if you have a Customer
object that exists in the Library namespace, there is no guarantee that it will be deserialized
into an object of the same type.
Q3 Which one of the following occurs when a struct type is cast to an interface that it
implements?
506
A. The original value type variable is destroyed.
B. A trappable InvalidCastException runtime error occurs.
C. A compiler error occurs; struct types cannot implement an interface.
D. The struct type is boxed and a new reference type created.
E. The original value type is cloned using the ValueType class' implementation of
IClonable.
D But yes you can implement interface in structures. As interface can be only reference
types so it will boxed.
Q4
internal class Piston {}
internal class Engine
{
private Piston[] myPistons = new Piston[4];
public bool Ignition() {
/ / some code
}
}
public class Car
{
private Engine myEngine = new Engine();
public void Start()
{
/ / put in keys etc..
if (myEngine.Ignition()) {
/ / some more code
507
}
}
}
What concept does the above sample code demonstrate?
A. Delegation
B. Composition
C. Polymorphism
D. Combination
E. Inheritance
B
Q5. As a developer you are displaying product data from SQL Server. Product table has
Productid and ProductName. You write ADO.NET code that uses a SqlDataAdapter
object and a SqlCommand object to retrieve the product data from the database by calling
a stored procedure. You set the CommandType property of the SqlCommand object to
CommandType.StoredProcedure. You set the CommandText property of the object to
procProductList. Your code successfully files a DataTable object with a list of products
that is sorted by ProductID in descending order.
You want the data to be displayed in reverse alphabetic order by ProductName.
What should you do?
A. Set the command text to "SELECT * FROM procProductList ORDER BY
ProductName DESC;" then bind the DataGrid control to the DataTable object.
B. Create a new DataView object based on the DataTable object.
C. Set the Sort Property of the DataView object to ProductName DESC.
D. Bind the DataGrid control to the DataView object.
E. Set the AllowSorting property of the DataGrid control to True.
508
F. Set the SortExpression property of the DataGridColumn that displays ProductName
to bind the DataGrid control to the DataTable object.
G. Set the DisplayExpression property of the DataTable object to ORDER BY
ProductName DESC. Bind the DataGrid control to the DataTable object.
Answer A
Q6. What is the fastest way to concat strings in ASP.NET ? What should you do?
A. Write code that uses the Append method of the StringBuilder object.
B. Write code that uses the Substring method of the String object.
C. Write code that uses the Concat method of the String object.
D. Write code that uses the plus-sign (+) operator to concatenate the strings.
Answer: A
Q7. "Virtual Software public limited" wants to connect to SQL Server 6.5 using ASP.NET
?
A. Use a SqlConnection object to connect to the database, and use a SqlCommand object
to run a stored procedure that returns the data.
B. Use an OleDbConnection object to connect to the database, and use an
OleDbCommand object to run a stored procedure that returns the data.
C. Configure SQL Server to support HTTP access, and create an XML template to run a
stored procedure that returns the data in XML format.
D. Use COM interop to create an ADODB.Connection object, and use an
ADODB.Command object to run a SQL statement that returns the data.
Answer B
You can not use SQL Server .NET Data Provider for SQL Server 6.5. Its only for SQL
7.0 and later
509
Q8. You want to only get changed data in a dataset which of the below is the best way ?
A. productInfo.GetChanges(DataRowState.Detached);
B. productChanges = productInfo.GetChanges();
C. productChanges.Merge(productInfo, true);
D. productChanges.Merge(productInfo, false);
Answer: B
Q9. Which of the following does the actual .NET code execute ?
A MSIL
B CLS
C CLR
D C#
E CTS
Ans :- C
Q10. Hiding implementation and exposing the interface in OOP's is called as :-
A) Polymorphism
B) Encapsulation
C) Overloading
D) Static
Ans :- B
Q11. Garbage collector runs ?
1) When Application is running for more than 30 minutes.
2) Every 1/ 4th Milli Second.
510
3) When application is running low of memory.
4) Its very random and takes random time from the CPU clock.
Ans :- 3
Q12. Which line is invalid in the code below ?
1. interface Test2
2. {
3. int i;
4. void Method2A(int);
5. string Method2B ();
6. }
A. Line 3
B. Line 4
C. Line 5
Answer :- A
Q13. You want to debug a Web-based ASP.NET application. But for some cause debugging
information is not shown. What could be missing?
A. <%@ Page Debug="true" %>
B. <%@ Application Debug="true" %>
C. <%@ Page Trace="true" %>
D. <%@ Application Trace="true" %>
Answer :- A.
511
Q14. What property is used on the DataTable to indicate conflicts after update method is
called?
A. HasErrorConflict
B. HasError
C. HasCollision
D. HasDataError
Answer :- A
Q15. What is a DiffGram?
A. XML file containing both the original and current values for the data.
B. XML file containing the difference between original and current data.
C. DataSet loaded with two XML files, resulting in the difference being current.
D. DataSet loaded with an XML file and the original values from the data source.
Answer :- A
What ASP.NET object encapsulates the state of the client and the browser?
A. Application object.
B. Session object.
C. Response object.
D. Request object.
E. Server object
Answer :- B
Q16. What method(s) must be used with the Application object to ensure that only one
process accesses a variable at a time?
A. Synchronize()
B. Lock() and UnLock()
512
C. ThreadLock
D. Synchronize.
Answer :- B
Q17. Which object can help you maintain data across users?
A. The Session object.
B. The Application object.
C. The Response object.
D. The Request object.
E. The Server object
Answer :- B
Q18. What must be done before you can consume a web service?
A. Build a proxy library by using the TblImp.exe utility.
B. Build a proxy library by using the Disc.exe utility.
C. Build a proxy library by using the csc.exe utility.
D. Build a proxy library by using the wsdl.exe utility
Answer :- D
Q19. What control is used to validate that two fields are equal?
A. RequiredFieldValidator
B. RegularExpressionValidator
C. CompareValidator
D. The equals() method of the field.
Answer :- C
513
Q20. Why should you close all database objects and set them to NULL before leaving the
method where the objects were created?
A. To ensure that the objects destructors are called.
B. To ensure that the connection to the database is closed as soon as possible.
C. To ensure that the objects can be reused.
D. Good coding practice.
Answer :- B
Q21. You are developing a web application that is retrieving historical library information
from a database server and displays it to the users of your application. What cache strategy
will give you the best performance?
A. Use the output cache.
B. Use the cache object.
C. Use the ASP.NET central cache.
D. Use the client cache
Answer :- B
Q22. Which tool can you use to precompile a Windows application?
A. mscorcfg.msc
B. ngen.exe
C. caspol.exe
Answer :- B
Q23. Which method of the ServiceController class will allow you to send a command to
the service?
514
A. Stop()
B. Start()
C. Pause()
D. ExecuteCommand()
Answer :- D
Q24. .NET remote server object must implement?
A. IUnknown
B. IMarshalByValue
C. IMarshalByRef
D. ISingleCall
E. ISerializable
Answer :- E
Q25. You are in charge of creating a remote object that will return database records to
the caller of the method. You want to keep track of the number of requests. Which
activation mode would you use?
A. SingleCall
B. Singleton
C. Client-activated
D. Server-activated
Answer :- B
515
Q26. You want to ensure that your web method uses the cache for results, so you change
the web method attribute to [WebMethod(BufferResponse = true)]. When you investigate,
you find that your web method still is not using the cache. What is the most effective way
of ensuring that your web method uses the cache?
A. Add CacheTime=300 to the WebMethod attribute.
B. Add Cache=true to the WebMethod attribute.
C. Add EnableCache=true to the WebMethod attribute.
D. Add CacheDuration=300 as a parameter to the WebMethod attribute.
Answer :- D
Q27. What namespace must be used in order to use the DOM for XML support?
A. System.Data.Xml
B. System.Xml
C. System.Xml.DOM
D. System.DOM
Answer :- B
Q28. You need to encrypt the SOAP header. What is the correct method to use?
A. Inherit the web service class from the SoapHeaderEncrypt class.
B. Custom SOAP headers.
C. SOAP header extensions.
D. Enable SSL for the XML web service and configure it to encrypt the headers.
Answer :- C
516
17. Free exams
(Thanks to www.measureup.com click on demo link its decent.)
http:/ / cybermediadice.measureup.com/ cart/ displayproducts.asp
517
18. Pending Topics
I have made an attempt to cover most of the topics. But still there are lot of important
topics pending which can turn the tables around. As this been a interview book its also
important to notify the readers what it did not cover and are important for .NET
Interviews.
Crystal reports. As reporting services has taken over the full market of reports I
have covered a complete chapter in SQL Server Interview question book. But still
there are organization who ask crystal reports even today. So just in case brush you
skills regarding the same.
* Setup and Packaging.
* VSTS
* Biztalk Server.
Sharepoint.
Commerce Server.
All topics marked with * will be covered in the third edition.If you feel that something
very important and basic not covered in the book mail at shiv_koirala@yahoo.com. I will
make a attempt to close it in the third edition.