Tuesday, January 27, 2009

Filling data from Database in to Dataset and then to Datagrid

Dataset can not directly retrieve data from database. For this purpose we should use DataAdapter. DataAdapter acts as a bridge between database and dataset. This is used to retrieve data from Database into Dataset as well as to Update Database through Dataset.It supports insert, delete, update, select operations. It supports disconnected model.

Now we will see the steps required to fill data from database into dataset and then populate that data into datagrid.
For that

In .aspx page, in <div> section we should write
<asp:datagrid id="exdatagrid" autogeneratecolumns="true" runat="server">

Here ID represents the id of the datagrid, runat represents that the datagrid is a server control, AutoGenerateColumns automatically creates the columns for the datagrid.

In the .aspx.cs file

1. First we should open a connection
SqlConnection newconn = new SqlConnection(“Server=xxx;InitialCatalog=xxx;

In the above statement server = xxx means we are specifying server name. InitialCatalog means database name from which we want to retrive data. Userid, password are userid and passwords of user for sql server.

2. Next we need to specify the sql statement(required operation)

SqlCommand cmd = new SqlCommand(“select * from xxx”, newconn);

In this statement first argument specifies the sql select statement(required operation) and second statement specifies the connection object. Here xxx represents Table name in database.

3 Now, we need to declare the DataAdapter

SqlDataAdapter da = new SqlDataAdapter(cmd);

In this statement dataadapter contains the command object as its argument to perform the required operation.

4. Now, we need to fill the dataset

ds = new DataSet();

In these statements first we declare dataset and then using the Fill() method of dataadapter we fill the dataset with the data from Database.

so now dataset is filled with the data from database.

5. Now we fill datagrid with the information/data in the dataset

exdatagrid.DataSource = ds;

Here exdatagrid is the id of the datagrid we have declared in .aspx page.
DataSource property represents the datasource(means dataset) for the datagrid. DataBind method is used to bind data to the datagrid.

That’s it. We will see the data populated in to the datagrid.

Tuesday, January 20, 2009

Interview Questions - Part 10

Interview Questions

96. What is a TreeView Server control ?
a ) This is a site navigation control. It displays the data in hierarchical order. Generally is is used to display Menu items for an application. It contains a number of prebuilt styles.

97. What are the differences between viewstate and hidden fields?
a ) Viewstate :
1. This is used for pages that will postback to itself
2. This is a built in structure for maintaining state of a page
3. Security is more as data is hashed, compressed and encoded.
Hiddenfield :
1. This is used for pages that will postback to itself or to another page
2. This is not an inbuilt structure
3. Security is less when compared to viewstate

98. Examples of Navigation controls?
a ) They are
1. TreeView Control
2. Menu
3. SiteMapPath

99. What is the namespace used for web page
a ) System.Web.UI.Page

100. What is the use of IsPostBack method?
a ) This method is to determine whether request is new request or postback request.

101. What are the advantages of DataGrid Control?
a )
1. Inbuilt support for paging and sorting
2. Inbuilt support for user selection and editing
3. Contains its default display

Wednesday, January 14, 2009

Interview Questions - Part 9

Interview Questions
86. What is caching?
a ) This allows a way to keep most frequently used data in memory to increase the performance of the application.

87. What are the types of page output cache?
a ) This is used to store the contents of a processed page in memory.
It is devided in to 2 types
1. full page caching
it stores the entire contents of a page
2. partial page caching
it stores the parts of a page.

88. What do you mean by post-cache substitution?
a ) This is one type of partial page caching. It allows you to cache the entire page but parts of a page are not cached means they will be created dynamically.

89. When the items will be removed from the cache?
a ) Items from cache are removed
1. when memory runs low
2. when an item expires
3. when items dependency changes

90. What is Sliding expiration?
a ) Suppose an item is placed in cache and its sliding expiration is 10 minutes. Then this sliding expiration policy specifies that the item stored in cache will be removed after 10 min from the time it is last used/accessed.

91. What is Absolute expiration?
a ) Suppose an item is placed in cache and its absolute expiration is 5 pm. Then this absolute expiration policy specifies that the item will be removed from the cache after 5 pm.

92. What is the directive used to implement caching in a page?
a ) It is @OutputCache

93. What is the attribute used to set the expiration of an item in the cache?
a ) It is “Duration” attribute

94. What are the attributes of outputcache used to store multiple versions of a page?
a )
1. VaryByParam
Using querystring it enables you to cache multiple versions of a page
2. varyByControl
Using a control value it enables you to cache multiple versions of a page
3. VaryByHeader
Using requests http header it enables you to cache multiple versions of a page
4. VaryByCustom
Using custom string or browser type it enables you to cache multiple versions of a page

95. what is sql dependency in caching?
a ) Means an item in the cache depends on the changes in a table in sql Database.

Saturday, January 10, 2009

Interview Questions - Part 8

Interview Questions

76. What is the life time of the data stored in viewstate?
a ) Data stored in viewstate exists for the life of the current page.

77. Can a masterpage contain multiple content areas?
a ) Yes

78. What does the merge method of dataset do?
a ) It merges the dataset with another dataset.

79. What is the maximum length of the char datatype?
a ) Char – max of 8000 characters

80. What is the method used to kill a session explicitly?
a ) Session.abandon method.

81. What is the extension of the resource files?
a ) .resx

82. What is the attribute used to apply theme to a specific page?
a ) That is ‘Theme’ attribute.

83. How many types of configuration files are there?
a ) 2 types
Machine.config: This is a server or machine wide configuration file
Web.config : This is a application configuration file.

84. What are the advantages of web.config file?
a )
1. This contains application specific configuration settings whichis same for all the pages in that application.
2. This is xml file which is easily readble and understandable.
3. This applies changes to the asp.net application with out need for the administrator to stop and start the webserver.
4. It provides more security as data is encrypted.

85. Is it possible for an application to have more than one web.config file?
a ) Yes. An application can support more than one web.config file.

Thursday, January 8, 2009

Interview Questions - Part 7

Interview Question

66. What are the types of Serialization?
a ) 4 types
1. XML Serialization
2. Binary Serialization
3. SOAP Serialization
4. Custom Serialization

67. What is xml serialization?
a. ) Xml serialization can convert only the public properties and fields of an object in to an xml stream that confirms to a specific xml schema defination language document. Xml serialization is also known as shallow serialization. Xml serialization is used when you nedd the data in the object to stored in xml format. Xml stream can be processed by any application as needed regardless of platform.

68. What are the 2 methods of xmlserializer class?
a ) 1. serialize
2. deserialize

69. What is binary serialization?
a ) This is used to convert both public and private properties and fields of an object. This serialization is useful when data needs to travel electronically over wire. Disadvantage of this serialization is it is not easily portable to another platform.

70. What is SOAP Serialization?
a ) Similar to binary serialization this also convert the public and private properties and fields of an object in to a stream of bytes. This serialization is useful when you need interoperability.

71. what is satellite assembly?
a) An assembly which contains language specific resouces means culture information is known as satellite assembly.

72. what are the parts of version number of an assembly?
a) They are major, minor, revision, build.

73. what are the commands used to insert and remove assemblies in/from global assembly cache?
a) gacutil -I assemblyname /to insert
gacutil -u assemblyname /to uninstall

74. In which suituations we use gacutil tool?
a) We use it in development scenarios.

75. what is side-by-side execution?
a) This provides a way to keep multiple versions of an application on the same machine at the same time.

Monday, January 5, 2009

Interview Questions - Part 6

Interview Questions

56. How can we customise columns in datagrid?
a ) Using the Template column.

57. What is the character/size limit in query string?
a ) Some browsers impose a 2083 character limit on the length of the URL.

58. How do you separate business logic while creating on asp.net application?
a ) By using code behind model

59. How many classes can a single .net dll contain?
a ) It can contain unlimitesd classes.

60. What is the maximum length of varchar and nchar datatypes?
a ) Varchar - max of 8000 characters
Nchar - max of 4000 characters

61. What is Portable Executable?
a ) It is a file format defining the structure that all executable files and dynamic link libraries must use to allow them to be loaded and executed by windows.

62. What is the use of Application Domain?
a ) This provides a way to isolate an application from other applications.

63. In which folder we store Local Resouce files?
a ) They are specific to a single page. They are stored in App_LocalResorces

64. What is serialization? What are its advantages?
a ) It provides a way to save the state of an object by converting it into a stream of bytes.
1. It provides a way to transportation of an object through a network
2. It provides a way to re create the same object by saving the its state.

65. What are the disadvantages of serialization?
a )
1. It requires more resources (to convert an object into a stream of bytes)
2. Serialization is a slow process.
3. It involves latency issues for transmitting the data over network.