Archive for the ‘aspx’ Category

Using connectionString

December 3, 2007

<connectionStrings>
<add name=”demowebdb” connectionString=”Data Source=SIMANTA\SQLEXPRESS;user id=sa;pwd=root;database=testdb” providerName=”System.Data.SqlClient” />
<!–<add name=”demowebdb” connectionString=”Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\demoweb.mdf;Integrated Security=True;User Instance=True” providerName=”System.Data.SqlClient”/>–>
</connectionStrings>

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

<%@ Page Language=”C#” Debug=”true” %>
<%@ Import Namespace=”System.Data” %>
<%@ Import Namespace=”System.Data.SqlClient” %>
<%@ Import Namespace=”System.Configuration” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<script runat=”server”>
public class Program
{
public int sqlInsert()
{
string connstr = ConfigurationManager.ConnectionStrings["demowebdb"].ConnectionString;
string query = “INSERT INTO employee(fname,lname,gender,createdate,isactive) VALUES(‘t’’s’,'tt’,'M’,'”+ DateTime.Now +”‘,1)”;
SqlConnection dbconn = new SqlConnection(connstr);
dbconn.Open();
SqlCommand cmd = new SqlCommand(query, dbconn);
int numrows = cmd.ExecuteNonQuery();
dbconn.Close();
return numrows;
}
}
</script>

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>SQLConnection Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<%
Program p = new Program();
Response.Write(p.sqlInsert());
%>
</div>
</form>
</body>
</html>

OOPs and basic concept

November 14, 2007

Accessor: A method that sets or retrieves the value of a private data member value that is associated with a property. Read-write properties have get and set accessors. Properties that are read-only have only a get accessor.

Constructor: A special method on a class or struct that initializes the objects of that type.

Destructor: A special method on a class or struct that prepares the instance for destruction by the system.

Field: A data member of a class or struct that is accessed directly.

Generics: Generics allow you to define a class and or method that are defined with a type Parameter. When client code instantiates the type, it specifies a particular type as an argument.

Property: A data member accessed by means of an accessor.

Refactoring: Reusing previously entered code.

Q. What is polymorphism?
Q. What are the difference between Abstruct class and Interface?
* An Interface cannot implement methods.
* An abstract class can implement methods.

* An Interface can only inherit from another Interface.
* An abstract class can inherit from a class and one or more interfaces.

* An Interface cannot contain fields.
* An abstract class can contain fields.

* An Interface can contain property definitions.
* An abstract class can implement a property.

* An Interface cannot contain constructors or destructors.
* An abstract class can contain constructors or destructors.

* An Interface can be inherited from by structures.
* An abstract class cannot be inherited from by structures.

* An Interface can support multiple inheritance.
* An abstract class cannot support multiple inheritance.

Q. What is WSDL?
ANS: WSDL stands for Web Services Description Language which is an XML document used to describe Web services and also used to locate Web services.

Q. Describe ASP.NET page lifecycle.
ANS:
Page request:
The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.

Start:
In the start step, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. Additionally, during the start step, the page’s UICulture property is set.

Page initialization:
During page initialization, controls on the page are available and each control’s UniqueID property is set. Any themes are also applied to the page. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.

Load:
During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.

Validation:
During validation, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page.

Postback event handling:
If the request is a postback, any event handlers are called.

Rendering:
Before rendering, view state is saved for the page and all controls. During the rendering phase, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream of the page’s Response property.

Unload:
Unload is called after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and any cleanup is performed.

PAGE EVENTS:
PreInit -> Init -> InitComplete -> PreLoad -> Load -> [Control events] -> LoadComplete -> PreRender -> SaveStateComplete -> Render -> Unload.

Q. What is sealed class? How is it different from private class?
Q. What are the difference between char and varchar?
ANS: The CHAR is a fixed-length character data type, the VARCHAR is a variable-length character data type. CHAR should be used for storing fix length character strings. String values will be space/blank padded before stored on disk. If this type is used to store variable length strings, it will waste a lot of disk space.

Q. What are cursor, view and trigger?
Cursors are special programming constructs that allow data to be manipulated on a row-by-row basis, similar to other structured programming languages. They are declared like a variable, and then move one record at a time using a loop for control. There are three types of cursors, DYNAMIC, STATIC, and KEYSET. There are also three types of locks for cursors, READ ONLY, SCROLL LOCKS, and OPTIMISTIC.
Benefit – Fetch more records at time for that purpose you can use Cursor.

A View is a logical construct in the database. You basically create a virtual table in the database with a pre-defined query. Any other query can use the view.

Triggers are a special PL/SQL construct similar to procedures. However, a procedure is executed explicitly from another block via a procedure call, while a trigger is executed implicitly whenever the triggering event happens. The triggering event is an INSERT, DELETE, or UPDATE command. The timing can be either BEFORE or AFTER. The trigger can be either row-level or statement-level, where the former fires once for each row affected by the triggering statement and the latter fires once for the whole statement.

Q. What are the difference between primary key and unique key?
*Primary key should not contain nulls but unique key can contains null values.
*There is only one Primary key for one table but there may be more than one
Unique Key in a table.

Q. What is indexing?
Indexes are database tools that increase the system’s ability to retrieve data by not scanning all of the data records in search of the desired record(s). Indexes can change the organization of data so that it is structured similarly to how it will be accessed for retrieval. The indexes are created on column(s) to help the database find data based upon the value(s) contained in those indexed column(s).
Index Drawbacks:
Indexes are a performance drag when the time comes to modify records. Any time a query modifies the data in a table the indexes on the data must change also. Achieving the right number of indexes will require testing and monitoring of your database to see where the best balance lies. Static systems, where databases are used heavily for reporting, can afford more indexes to support the read only queries. A database with a heavy number of transactions to modify data will need fewer indexes to allow for higher throughput. Indexes also use disk space. The exact size will depends on the number of records in the table as well as the number and size of the columns in the index. Generally this is not a major concern as disk space is easy to trade for better performance.

Q. How do you remove duplicate entries from a table?
ANS:
EMPID EMPNAME EMPSSN
———- ———- ———–
1 Jack 555-55-5555
2 Joe 555-56-5555
3 Fred 555-57-5555
4 Mike 555-58-5555
5 Cathy 555-59-5555
6 Lisa 555-70-5555
7 Jack 555-55-5555
8 Mike 555-58-5555
9 Cathy 555-59-5555
10 Lisa 555-70-5555
11 Lisa 555-70-5555

delete from employee
where (empid, empssn)
not in
( select min(empid), empssn
from employee group by empssn); => EMPID Unique.

delete from employee
where (rowid, empssn)
not in
(select min(rowid), empssn from employee group by empssn); => Duplicate records once again but this time the empids and empSSNs are the same.

Q. What is MDAC (Microsoft Data Access Components)?
ANS: ADO, ODBC and OLE DB

Q. Difference between Application and Session?
An application variable exists from when the application is first ‘run’ (The first time a page in the app is used) and exists until the application is stopped on the server, either through IIS or the actual machine being turned off or rebooted.
A session variable is created for the instance of the browser accessing the site and will only be available until that browser is closed or the session times out.

Q. Assemblies:
An assembly is a fundamental building block of any .NET Framework application. For example, when you build a simple C# application, Visual Studio creates an assembly in the form of a single portable executable (PE) file, specifically an EXE or DLL.

Assemblies contain metadata that describe their own internal version number and details of all the data and object types they contain. This is known as Assembly Manifest.

Assemblies have the following properties:

*Assemblies are implemented as .exe or .dll files.

*You can share an assembly between applications by putting it in the Global Assembly Cache.

*Assemblies must be strong-named before they can be included in the Global Assembly Cache.

*Assemblies are only loaded into memory if they are required.

*You can programmatically obtain information about an assembly by using reflection.

*You can use two versions of the same assembly in a single application.

A private assembly is an assembly that is deployed with an application and is available for the exclusive use of that application. That is, other applications do not share the private assembly. Private assemblies are one of the methods that can be used to create isolated applications.

A shared assembly is an assembly available for use by multiple applications on the computer.

Difference:
* A private assembly is not required to be signed, and publickeyToken is not required in the <assemblyIdentity> element of the assembly manifest.
* Private assemblies can be installed into the application’s folder using any installation technology. Private assemblies are not required to be installed using the Windows Installer.

Q. Five(5) new features added in ASP.NET 2.0.
1. Master Page
2. App_Code
3. App_Data
4. Themes and Skins
5. <%$ … %>
6. 64-Bit Support

ASP.NET Questions

October 29, 2007

1. Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process.
inetinfo.exe is theMicrosoft IIS server running, handling ASP.NET requests among other things.When an ASP.NET request is received (usually a file with .aspx extension), the ISAPI filter aspnet_isapi.dll takes care of it by passing the request tothe actual worker process aspnet_wp.exe.

2. What’s the difference between Response.Write() andResponse.Output.Write()?
Response.Output.Write() allows you to write formatted output.

3. What methods are fired during the page load?
Init() – when the page is instantiated
Load() – when the page is loaded into server memory
PreRender() – the brief moment before the page is displayed to the user as HTML
Unload() – when page finishes loading.

4. When during the page processing cycle is ViewState available?
After the Init() and before the Page_Load(), or OnLoad() for a control.

5. What namespace does the Web page belong in the .NET Framework class hierarchy?
System.Web.UI.Page

6. Where do you store the information about the user’s locale?
System.Web.UI.Page.Culture

7. What’s the difference between Codebehind=”MyCode.aspx.cs” andsrc=”MyCode.aspx.cs”?
CodeBehind is relevant to Visual Studio.NET only.

8. What’s a bubbled event?
When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.

9. Suppose you want a certain ASP.NET function executed on MouseOver for a certain button. Where do you add an event handler?
Add an OnMouseOver attribute to the button. Example: btnSubmit.Attributes.Add(“onmouseover”,”someClientCodeHere();”);

10. What data types do the RangeValidator control support?
Integer, String, and Date.

11. Explain the differences between Server-side and Client-side code?
Server-side code executes on the server. Client-side code executes in the client’s browser.

12. What type of code (server or client) is found in a Code-Behind class?
The answer is server-side code since code-behind is executed on the server. However, during the code-behind’s execution on the server, it can render client-side code such as JavaScript to be processed in the clients browser. But just to be clear, code-behind executes on the server, thus making it server-side code.

13. Should user input data validation occur server-side or client-side? Why?
All user input data validation should occur on the server at a minimum. Additionally, client-side validation can be performed where deemed appropriate and feasable to provide a richer, more responsive experience for the user.

14. What is the difference between Server.Transfer and Response.Redirect? Why would I choose one over the other?
Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client’s browser. This provides a faster response with a little less overhead on the server. Server.Transfer does not update the clients url history list or current url. Response.Redirect is used to redirect the user’s browser to another page or site. This performas a trip back to the client where the client’s browser is redirected to the new page. The user’s browser history list is updated to reflect the new address.

15. Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?
Valid answers are:
· A DataSet can represent an entire relational database in memory, complete with tables, relations, and views.
· A DataSet is designed to work without any continuing connection to the original data source.
· Data in a DataSet is bulk-loaded, rather than being loaded on demand.
· There’s no concept of cursor types in a DataSet.
· DataSets have no current record pointer You can use For Each loops to move through the data.
· You can store many edits in a DataSet, and write them to the original data source in a single operation.
· Though the DataSet is universal, other objects in ADO.NET come in different versions for different data sources.

16. What is the Global.asax used for?
The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.

17. What are the Application_Start and Session_Start subroutines used for?
This is where you can set the specific variables for the Application and Session objects.

18. Can you explain what inheritance is and an example of when you might use it?
When you want to inherit (use the functionality of) another class. Example: With a base class named Employee, a Manager class could be derived from the Employee base class.

19. Whats an assembly?
Assemblies are the building blocks of the .NET framework. Overview of assemblies from MSDN

20. Describe the difference between inline and code behind.
Inline code written along side the html in a page. Code-behind is code written in a separate file and referenced by the .aspx page.

21. Explain what a diffgram is, and a good use for one?
The DiffGram is one of the two XML formats that you can use to render DataSet object contents to XML. A good use is reading database data to an XML file to be sent to a Web Service.

22. Whats MSIL, and why should my developers need an appreciation of it if at all?
MSIL is the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL. MSIL also allows the .NET Framework to JIT compile the assembly on the installed computer.

23. Which method do you invoke on the DataAdapter control to load your generated dataset with data?
The Fill() method.

24. Can you edit data in the Repeater control?
No, it just reads the information from its data source.

25. Which template must you provide, in order to display data in a Repeater control?
ItemTemplate.

26. How can you provide an alternating color scheme in a Repeater control?
Use the AlternatingItemTemplate.

27. What property must you set, and what method must you call in your code, in order to bind the data from a data source to the Repeater control?
You must set the DataSource property and call the DataBind method.

28. What base class do all Web Forms inherit from?
The Page class.

29. Name two properties common in every validation control?
ControlToValidate property and Text property.

30. Which property on a Combo Box do you set with a column name, prior to setting the DataSource, to display data in the combo box?
DataTextField property.

31. Which control would you use if you needed to make sure the values in two different controls matched?
CompareValidator control.

32. How many classes can a single .NET DLL contain?
It can contain many classes.

Web Service Questions

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

2. True or False: A Web service can only be written in .NET?
False

3. What does WSDL stand for?
Web Services Description Language.

4. Where on the Internet would you look for Web services?
http://www.uddi.org

5. True or False: To test a Web service you must create a Windows application or Web application to consume this service?
False, the web service comes with a test page and it provides HTTP-GET method to test.

State Management Questions

1. What is ViewState?
ViewState allows the state of objects (serializable) to be stored in a hidden field on the page. ViewState is transported to the client and back to the server, and is not stored on the server or any other external source. ViewState is used the retain the state of server-side objects between postabacks.

2. What is the lifespan for items stored in ViewState?
Item stored in ViewState exist for the life of the current page. This includes postbacks (to the same page).

3. What does the “EnableViewState” property do? Why would I want it on or off?
It allows the page to save the users input on a form across postbacks. It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser. When the page is posted back to the server the server control is recreated with the state stored in viewstate.

4. What are the different types of Session state management options available with ASP.NET?
ASP.NET provides In-Process and Out-of-Process state management. In-Process stores the session in memory on the web server. This requires the a “sticky-server” (or no load-balancing) so that the user is always reconnected to the same web server. Out-of-Process Session state management stores data in an external data source. The external data source may be either a SQL Server or a State Server service. Out-of-Process state management requires that all objects stored in session are serializable.