HI WELCOME TO SIRIS

asp.net interview questions part2

Leave a Comment

What is the process for strong naming an assembly

What is the process for strong naming an assembly ?
or
What is the purpose of strong naming tool ( sn.exe ) in .NET ?

In .NET, the assembly name usually consists of 4 parts as listed below.
1. Simple Textual Name
2. Version Number (The version number is also divided into 4 parts)
3. Culture
4. Public Key Token 

If an assembly contains, all the 4 parts, then the assembly is a strongly named assembly, other wise the assembly is called as a weak named assembly. In general, when you compile any .NET application, the generated assembly by default will have the Simple Textual Name, Version Number and Culture but not the public key token. If you have to sign the assembly with a public key token, you first have to generate the key pair using key generation tool called strong naming tool (sn.exe). The generated key pair will consist of aprivate and a public key and are written into a key file. Key files have the extension of .snk

We now have to associate the key file with the project, so that when we compile the project, the generated assembly is signed using the key pair. To do this, In AssemblyInfo.cs file of the project, specifyAssemblyKeyFile attribute as shown below.
              [assembly: AssemblyKeyFile("MyKey.snk")]

The last and final step is to build the project which will automatically sign the assembly using the key file. This process generates the strongly named assembly.

In short, there are 3 simple steps to generate a strongly named assembly.
1. Generate the key pair using strong naming tool, SN.exe.

2. Associate the generated Key file to the project using AssemblyKeyFile, which is present in AssemblyInfo.cs file.

3. Build the project.

Once, you have strongly named the assembly, you can copy it to GAC. There are 2 ways to copy an assembly into GAC.
1. Using simple drag and drop : Drag the generated assembly into the GAC folder. Usually the path for GAC is c:\windows\assembly. On some machines this could be c:\winnt\assembly.

2. Use GAC utility : Use GAC Utility tool(gacutil.exe) as shown below in visual studio command prompt. 
               gacutil.exe -i C:\MyAssembly.dll (- i stands for install)

Once, you have successfuly copied the assembly into GAC, notice the four parts of the assembly name. Theculture column could be empty, indicating that the assembly is language neutral. 

Please click here to read few other follow up interview questions related to strong named assemblies.

Interview Questions related to strong named assemblies

Can you copy a weak named assembly into GAC?
No, an assembly has to be strongly named to be copied into the GAC

What is the difference between a strong and weak named assemblies?
The following are the differences between a strong and weak named assemblies
1. Weak named assemblies can be duplicated and tampered with, where as strong named assemblies cannoth be tampered and duplicated. 

2. Strong named assemblies can be copied into GAC, where as weak named assemblies cannot be copied.

3. A single copy of strong named assembly present in the GAC can be shared with multiple applications, where as weak named assembly must be copied into the bin directory of each project.

What is the main advantage of strong naming an assembly?
A shared assembly that is strongly named solves the DLL hell problem, that microsoft is notoriously known for. Please follow the articles below, to understand DLL hell and the solution.


Can a strong named assembly refer, a weak named assembly and why?
No, a strong named assembly cannot reference, another weak named assembly. If this is possible, the DLL hell problem will reoccur. 

Explantion: When you reference a strong named assembly, you expect to get certain benefits, such as versioning and naming protection. If the strong named assembly then references an assembly with a simple name, which does not have these benefits, you lose the benefits you would derive from using a strong named assembly and revert to DLL conflicts. Therefore, strong named assemblies can only reference other strong named assemblies.

What is the downside of strong naming an executable (.EXE) ?
A strongly named assembly cannot reference a weak named assembly. Therefore, strong naming an EXE prevents the EXE from referencing weak named dlls, that are deployed with the application. For this reason, the Visual Studio project system does not strong name application EXEs. Instead, it strong-names the Application manifest, which internally points to the weak named application EXE. In addition, you may want to avoid strong-naming components that are private to your application. In this case, strong-naming can make it more difficult to manage dependencies and add unnecessary overhead for private components.

How is the DLL HELL problem solved in .NET




In short, the dll hell problem is solved in .NET by signing the shared assemblies with strong name.

In dot net all the shared assemblies are usually in the GAC. GAC stands for Global Assembly Cache. The path for GAC is C:\[OperatingSystemDirectory]\assembly. For example on my computer the path is C:\WINDOWS\assembly. The image below shows the shared assemblies in the GAC.



Only strong named assemblies can be copied into GAC. Strong named assemblies in .NET has 4 pieces in its name as listed below.
1. Simple Textual Name
2. Version Number
3. Culture
4. Public Key Token

All these four pieces put together, is called as the fully qualified name of the assembly. In the GAC image above Accessibility assembly has aversion of 2.0.0.0.


Now consider the example below:
1. I have 2 applications, Application - A1 and Application - A2 which relies on the shared assembly Accessibility.dll (Version 2.0.0.0) as shown in the image below.


2. Now, I have a latest version of Application - A2 available on the internet.

3. I download the latest version of A2 and install it on my machine. 
4. This new installation copies a newer version of Accessibility.dll into the GAC with version 3.0.0.0.
5. So, in the GAC we now have 2 versions of Accessibility.dll. 
6. Application - A1 continues to use Accessibility.dll (version 2.0.0.0) and Application - A2 uses Accessibility.dll (version 3.0.0.0) 
7. So, now the assemblies are able to reside side by side in the GAC. For this reason dot net assemblies are also said to be supporting side by side execution.

What is DLL HELL in .NET

Let us try and understand DLL HELL problem with an example. Please refer to the image below. 



1. I have 2 applications, A1 and A2 installed on my computer. 

2. Both of these applications use shared assembly shared.dll

3. Now, I have a latest version of Application - A2 available on the internet.

4. I download the latest version of A2 and install it on my machine.

5. This new installation has over written Shared.dll, which is also used by Application - A1.

6. Application - A2 works fine, but A1 fails to work, because the newly installed Shared.dll is not backward compatible.

So, DLL HELL is a problem where one application will install a new version of the shared component that is not backward compatible with the version already on the machine, causing all the other existing applications that rely on the shared component to break. With .NET versioning we donot have DLL HELL problem any more.

What is the difference between layers and tiers



Layers refer to logical seperation of code. Logical layers help you organise your code better. For example an application can have the following layers.

1)Presentation Layer or UI Layer
2)Business Layer or Business Logic Layer
3)Data Access Layer or Data Layer

The aboove three layers reside in their own projects, may be 3 projects or even more. When we compile the projects we get the respective layer DLL. So we have 3 DLL's now.

Depending upon how we deploy our application, we may have 1 to 3 tiers. As we now have 3 DLL's, if we deploy all the DLL's on the same machine, then we have only 1 physical tier but 3 logical layers.

If we choose to deploy each DLL on a seperate machine, then we have 3 tiers and 3 layers.

So, Layers are a logical separation and Tiers are a physical separation. We can also say that, tiers are the physical deployment of layers.


Tiers:
1) Presenation Tier or UI Tier (Hosts the Presentation Layer or UI Layer). This can be considered as web server in case of an ASP.NET web application. 
2) Application Tier or Business Tier (Hosts Business Layer or Business Logic Layer). 
3) Data Access Tier or Data Tier (Hosts Data Access Layer or Data Layer).
4) Database Tier - SQL Server or Oracle (or any other database) which has tables, stored procedures and other database objects.

In general the following are the responsibilities of each layer or tier:

1)Presentation Layer or Tier is usually responsible for interacting with the user.
2)Business Layer or Tier is responsible for implementing the business logic of the application.
3)Data Access Layer or Tier is responsible for encapsulating the code that accesses the persistent data stores such as a relational database.

What are the advantages and disadvantages of a layered architecture

The following are the advantages of a layered architecture:

Layered architecture increases flexibility, maintainability, and scalability. In a Layered architecture we separate the user interface from the business logic, and the business logic from the data access logic. Separation of concerns among these logical layers and components is easily achieved with the help of layered architecture.

Multiple applications can reuse the components. For example if we want a windows user interface rather than a web browser interface, this can be done in an easy and fast way by just replacing the UI component. All the other components like business logic, data access and the database remains the same. Layered architecture allows to swap and reuse components at will.

Layered architecture enables teams to work on different parts of the application parallely with minimal dependencies on other teams.

Layered architecture enables develop loosely coupled systems.

Different components of the application can be independently deployed, maintained, and updated, on different time schedules.

Layered architecture also makes it possible to configure different levels of security to different components deployed on different boxes. sO Layered architecture, enables you to secure portions of the application behind the firewall and make other components accessible from the Internet.

Layered architecture also helps you to test the components independently of each other.

The following are the disadvantages of a layered architecture:                 

There might be a negative impact on the performance as we have the extra overhead of passing through layers instead of calling a component directly.

Development of user-intensive applications can sometime take longer if the layering prevents the use of user interface components that directly interact with the database.

The use of layers helps to control and encapsulate the complexity of large applications, but adds complexity to simple applications.

Changes to lower level interfaces tend to percolate to higher levels, especially if the relaxed layered approach is used.

What is the difference between const and static read-only member?


A const field must be initialized at the place where it is declared as shown in the example below.
class Program
{
      public const int Number = 100;
}
It is a compile time error to declare a const without a value. The code below will generate a compiler error stating "A const field requires a value to be provided"
class Program
{
      public const int Number;
}
It is a compile time error to change the value of a constant. The following code will generate a compiler error stating "The left-hand side of an assignment must be a variable, property or indexer"
class Program
{
     public const int Number = 100;
     static void Main()
     {
           Number = 200;
     }
}


It is not mandatory to initialize a static readonly field where it is declared. You can declare a static readonly field without an initial value and can later initialize the static field in a static constructor as shown below.
class Program
{
     public static readonly int Number;
     static Program()
     {
           Number = 100;
     }
}

Once a static readonly field is initialized, the value cannot be changed. The code below will generate a compiler error stating "A static readonly field cannot be assigned to (except in a static constructor or a variable initializer)"
class Program
{
       public static readonly int Number;
       static Program()
       {
             Number = 100;
       }
       static void Main()
       {
              Number = 200;
        }
}

In short, the difference is that static readonly field can be modified by the containing class, but const field can never be modified and must be initialized where it is declared. A static readonly field can be changed by the containing class using static constructor as shown below.
class Program
{
       // Initialize the static readonly field 
       // to an initial value of 100
          public static readonly int Number=100;
          static Program()
          {
               //Value changed to 200 in the static constructor
                 Number = 200;
          }
}

Linq Interview Questions Part 1



What is LINQ?
LINQ, or Language INtegrated Query, is a set of classes added to the .NET Framework 3.5. LINQ adds a rich, standardized query syntax to .NET programming languages that allows developers to interact with any type of data.

What are the advantages of using LINQ or Language INtegrated Query?

In any data driven application, you get data either from a Database, or an XML file or from collection classes. Prior to LINQ, working with each data source requires writing a different style of code. Moreover, working with external resources like data bases, XML files involves communicating with that external resource in some syntax specific to that resource. To retrieve data from a database you need to send it a string that contains the SQL query to execute, similarly, to work with an XML document involves specifying an XPath expression in the form of a string. The idea is that using LINQ you can work with disparate data sources using a similar style without having to know a separate syntax for communicating with the data source (e.g., SQL or XPath) and without having to resort to passing opaque strings to external resources.

In any data driven web application or windows application, we use database as a datasource for the application. In order to get data from the database and display it in a web or windows application, we typically do the following.
1. Prepare your SQL Statements.
2. Execute SQL Statements against the database.
3. Retrieve the results.
4. Populate the Business Objects.
5. Display the Data in the Web Form or Windows From.



In order to send a query to the database we must first establish a connection to the database. We then must encode the logic - the SQL query, its parameters, and the parameters' values - into strings that are supplied to the SqlCommand object. And because these inputs are encoded into opaque strings, there is no compile-time error checking and very limited debugging support. For example, if there is a spelling mistake in the SELECT query causing the Customets table name to be misspelled, this typographical error won't show up until runtime when this page is viewed in a web browser. These typographical errors are easy to make as there is no IntelliSense support. When we use LINQ, Visual Studio would display an error message alerting us about the incorrect table name.

Another mismatch between the programming language and the database is that the data returned by the database is transformed for us into objects accessible through the SqlDataReader, but these objects are not strongly-typed objects like we'd like. To get this data into strongly-typed objects we must write code ourselves that enumerates the database results and populates each record into a corresponding object. 

LINQ was designed to address all these issues. LINQ also offers a unified syntax for working with data, be it data from a database, an XML file, or a collection of objects. With LINQ you don't need to know the intricacies of SQL, the ins and outs of XPath, or various ways to work with a collection of objects. All you need be familiar with is LINQ's classes and the associated language enhancements centered around LINQ. 

In other words, LINQ provides type safety, IntelliSense support, compile-time error checking, and enhanced debugging scenarios when working with different datasources.

LINQ Interview Questions Part 2



What are the three main components of LINQ or Language INtegrated Query?
1. Standard Query Operators
2. Language Extensions
3. LINQ Providers

How are Standard Query Operators implemented in LINQ?
Standard Query Operators are implemented as extension methods in .NET Framework. These Standard Query Operators can be used to work with any collection of objects that implements the IEnumerable interface. A class that inherits from the IEnumerable interface must provide an enumerator for iterating over a collection of a specific type. All arrays implement IEnumerable. Also, most of the generic collection classes implement IEnumerableinterface.

How are Standard Query Operators useful in LINQ?
Standard Query Operators in LINQ can be used for working with collections for any of the following and more.
1. Get total count of elements in a collection.
2. Order the results of a collection.
3. Grouping.
4. Computing average.
5. Joining two collections based on matching keys.
6. Filter the results

List the important language extensions made in C# to make LINQ a reality?
1. Implicitly Typed Variables
2. Anonymous Types
3. Object Initializers
4. Lambda Expressions


What is the purpose of LINQ Providers in LINQ?
LINQ Providers are a set of classes that takes a LINQ query and dynamically generates a method that executes an equivalent query against a specific data source.

What are the four LINQ Providers that .NET Framework ships?
1. LINQ to Objects - Executes a LINQ query against a collection of objects
2. LINQ to XML - Executes an XPATH query against XML documents
3. LINQ to SQL - Executes LINQ queries against Microsoft SQL Server.
4. LINQ to DataSets - Executes LINQ queries against ADO.NET DataSets.


Write a program using LINQ to find the sum of first 5 prime numbers?

Best pactices in developing asp.net applications - Part 1


1. Remove unused private fields and functions.

2. Do not cast unnecessarily. Avoid duplicate casts where possible, since there is a cost associated with them.

3. Properties that return arrays are prone to code inefficiencies. Consider using a collection or making this a method.

4. To test for empty strings, check if String.Length is equal to zero. Constructs such as "".Equals(someString) and String.Empty.Equals(someString) are less efficient than testing the string length. Replace these with checks for someString.Length == 0.

5. Methods in the same type that differ only by return type can be difficult for developers and tools to properly recognize. When extending a type, be sure not to define new methods that differ from base type methods only by type.

6. Use stringbuilder instead of string types for string manipulation. 


7. Use String.Format instead of concatenating and appending strings.

8. Use Type.TryParse rather than Convert.ToDestinationType(). For example use int.TryParse() rather than Convert.ToInt32() which might throw an exception.

9. Override Equals() method wherever applicable in your classes.

10. Consider passing base types as parameters - Using base types as parameters to methods improves re-use of these methods if you only use methods & properties from the parameter's base class. E.g. use Stream instead of FileStream as a parameter when only calling Stream.Read(), this makes the method work on all kind of streams instead of just File streams.

Best pactices in developing asp.net applications - Part 2


1. Do not catch general exception types - You should not catch Exception or SystemException. Catching generic exception types can hide run-time problems from the library user, and can complicate debugging. You should catch only those exceptions that you can handle gracefully.

2. Use properties instead of visible instance fields.

3. Follow the same naming conventions accross the solution. 


4. Remove unwanted commented code, Indent code properly.

5. Use curly braces with in an if statement, even if there is a single statement in the if block. This will provide better readability.

6. Make sure to refactor your code to move the duplicated code to common reusable functions.

7. Move one time control settings into the .aspx page rather than having them in the code behind in if(!IsPostback) block.

8. Use inheritance whereever possible, which enables code reuse and also reduces the amount of code we have to write and test.

9. Move the reusable javascript functions to an external .js file instead of having them on the page.

10. For controls that are declarativley specified on the page, tie the event handlers to the controls events on the aspx page rather than initializing them in the codebehind. If the controls are built dynamically then we donot have a choice.

11. Make sure to check for nulls when using any type retrieved from a session, querystring or a database to avoid NullReferenceExceptions.

12. Use foreach loop instead of using for loop which may lead to out of boundary run time exceptions.

ASP.NET Interview Questions on Data Access Security


What are the best practices to follow to secure connection strings in an ASP.NET web application?
1. Always store connection strings in the site's Web.config file. Web.config is very secure. Users will not be able to access web.config from the browser.
2. Do not store connection strings as plain text. To help keep the connection to your database server secure, it is recommended that you encrypt connection string information in the configuration file.
3. Never store connection strings in an aspx page.
4. Never set connection strings as declarative properties of the SqlDataSource control or other data source controls.
Why is "Connecting to SQL Server using Integrated Security" considered a best practice?Connecting to SQL Server using integrated security instead of using an explicit user name and password, helps avoid the possibility of the connection string being compromised and your user ID and password being exposed.

What is the advantage of storing an XML file in the applications App_Data folder? 
The contents of the App_Data folder will not be returned in response to direct HTTP requests.

What is Script injection? 
A script injection attack attempts to send executable script to your application with the intent of having other users run it. A typical script injection attack sends script to a page that stores the script in a database, so that another user who views the data inadvertently runs the code.
What is SQL injection?A SQL injection attack attempts to compromise your database by creating SQL commands that are executed instead of, or in addition to, the commands that you have built into your application.What are the best practices to keep in mind when accepting user input on a web application?
1.
 Always use validation controls whenever possible to limit user input to acceptable values.
2. Always check the IsValid property of the aspx page. Run the server side code only if the IsValid property value is true. A value of false means that one or more validation controls have failed a validation check.
3. Always perform server side validation irrespective of client side validation being performed or not. This will protect your web application even if the client has by passed the client side validation by disabling javascript in the web browser.
4. Also make sure to re validate user input in the business logic layer of your application.
What are the steps to follow to avoid Script Injection attacks?
1.
 Encode user input with the HtmlEncode method. This method turns HTML into its text representation.
2. If you are using the GridView control with bound fields, set the BoundField object's HtmlEncode property to true. This causes the GridView control to encode user input when the row is in edit mode.
What are the steps to follow to avoid SQL Injection attacks?Always use parameterized queries or stored procedures instead of creating SQL commands by concatenating strings together.

Can you encrypt view state data of an aspx page? 
Yes, you encrypt view state data of an aspx page by setting the page's ViewStateEncryptionMode property to true.

ASP.NET Interview Questions on HTTP modules and HTTP Handlers



What is an HTTP Handler? 

An ASP.NET HTTP handler is the process (frequently referred to as the "endpoint") that runs in response to a request made to an ASP.NET Web application. The most common handler is an ASP.NET page handler that processes .aspx files. When users request an .aspx file, the request is processed by the page through the page handler. You can create your own HTTP handlers that render custom output to the browser.

What is HTTP module?An HTTP module is an assembly that is called on every request that is made to your application. HTTP modules are called as part of the ASP.NET request pipeline and have access to life-cycle events throughout the request. HTTP modules let you examine incoming and outgoing requests and take action based on the request.

What is the interface that you have to implement if you have to create a Custom HTTP Handler? 
Implement IHttpHandler interface to create a synchronous handler.
Implement IHttpAsyncHandler to create an asynchronous handler.

What is the difference between asynchronous and synchronous HTTP Handlers?synchronous handler does not return until it finishes processing the HTTP request for which it is called.

An asynchronous handler runs a process independently of sending a response to the user. Asynchronous handlers are useful when you must start an application process that might be lengthy and the user does not have to wait until it finishes before receiving a response from the server.

Which class is responsible for receiving and forwarding a request to the appropriate HTTP handler? 
IHttpHandlerFactory Class

Can you create your own custom HTTP handler factory class?
Yes, we can create a custom HTTP handler factory class by creating a class that implements the IHttpHandlerFactory interface.

What is the use of HTTP modules? 
HTTP modules are used to implement various application features, such as forms authentication, caching, session state, and client script services.

What is the difference between HTTP modules and HTTP handlers?An HTTP handler returns a response to a request that is identified by a file name extension or family of file name extensions. In contrast, an HTTP module is invoked for all requests and responses. It subscribes to event notifications in the request pipeline and lets you run code in registered event handlers. The tasks that a module is used for are general to an application and to all requests for resources in the application.

What is the common way to register an HTTP module?The common way to register an HTTP module is to have an entry in the application's Web.config file.

Much of the functionality of a module can be implemented in a global.asax file. When do you create an HTTP module over using Global.asax File? 
You create an HTTP module over using Global.asax file if the following conditions are true

1. You want to re-use the module in other applications.
2. You want to avoid putting complex code in the Global.asax file.
3. The module applies to all requests in the pipeline.

ASP.NET Interview Questions on Themes and Skins


What is a "theme" in ASP.NET?A "theme" is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in a Web application, across an entire Web application, or across all Web applications on a server.

What is the extension for a skin file? 
.skin
What are the 2 types of control skins in ASP.NET?
1. 
Default skins
2. Named skins
What is the difference between Named skins and Default skins?default skin automatically applies to all controls of the same type when a theme is applied to a page. A control skin is a default skin if it does not have a SkinID attribute. For example, if you create a default skin for a Calendar control, the control skin applies to all Calendar controls on pages that use the theme. (Default skins are matched exactly by control type, so that a Button control skin applies to all Button controls, but not to LinkButton controls or to controls that derive from the Button object.)

named skin is a control skin with a SkinID property set. Named skins do not automatically apply to controls by type. Instead, you explicitly apply a named skin to a control by setting the control's SkinID property. Creating named skins allows you to set different skins for different instances of the same control in an application.
What are the 3 levels at which a theme can be applied for a web application?
1
. At the page level - Use the Theme or StyleSheetTheme attribute of the @ Page directive.

2. At the application level - Can be applied to all pages in an application by setting the <pages> element in the application configuration file.

3. At the web server level - Define the <pages> element in machine.config file. This will apply the theme to all the web applications on that web server.
What is the name of the folder that contains the application themes?App_Themes

What is a global theme? 
global theme is a theme that you can apply to all the Web sites on a server. Global themes allow you to define an overall look for your domain when you maintain multiple Web sites on the same server.

What is the difference between themes and CSS? 
1. Themes can define many properties of a control or page, not just style properties. For example, using themes, you can specify the graphics for a TreeView control, the template layout of a GridView control, and so on.

2. Themes can include graphics.

3. Themes do not cascade the way style sheets do. By default, any property values defined in a theme referenced by a page's Theme property override the property values declaratively set on a control, unless you explicitly apply the theme using the StyleSheetTheme property.

4. Only one theme can be applied to each page. You cannot apply multiple themes to a page, unlike style sheets where multiple style sheets can be applied.
What are the security concerns to keep in mind when using themes?Themes can cause security issues when they are used on your Web site. Malicious themes can be used to:

1. Alter a control's behavior so that it does not behave as expected.

2. Inject client-side script, therefore posing a cross-site scripting risk.

3. Expose sensitive information.

4. The mitigations for these common threats are:

5. Protect the global and application theme directories with proper access control settings. Only trusted users should be allowed to write files to the theme directories.

6. Do not use themes from an untrusted source. Always examine any themes from outside your organization for malicious code before using them on you Web site.

7. Do not expose the theme name in query data. Malicious users could use this information to use themes that are unknown to the developer and thereby expose sensitive information.

ASP.NET Interview Questions on DataSet


What is a DataSet?
DataSet is an in-memory cache of data.

In which namespace is the DataSet class present? 
System.Data

Can you add more than one table to a dataset?
Yes

Can you enforce constarints and relations on tables inside a DataSet?
Yes, the DataSet consists of a collection of DataTable objects that you can relate to each other with DataRelation objects. You can also enforce data integrity in the DataSet by using the UniqueConstraint and ForeignKeyConstraint objects.

What happens when you invoke AcceptChanges() method on a DataSet? 
Invoking AcceptChanges() method on the DataSet causes AcceptChanges() method to be called on each table within the DataSet.

Both the DataRow and DataTable classes also have AcceptChanges() methods. Calling AcceptChanges() at the DataTable level causes the AcceptChanges method for each DataRow to be called.

When you call AcceptChanges on the DataSet, any DataRow objects still in edit-mode end their edits successfully. The RowState property of each DataRow also changes. Added and Modified rows become Unchanged, and Deleted rows are removed.

If the DataSet contains ForeignKeyConstraint objects, invoking the AcceptChanges method also causes the AcceptRejectRule to be enforced.

Is there a way to clear all the rows from all the tables in a DataSet at once?
Yes, use the DataSet.Clear() method to clear all the rows from all the tables in a DataSet at once.

What is the difference between DataSet.Copy() and DataSet.Clone()? 
DataSet.Clone() copies the structure of the DataSet, including all DataTable schemas, relations, and constraints. Does not copy any data.

DataSet.Copy() copies both the structure and data.

How do you get a copy of the DataSet containing all changes made to it since it was last loaded? 
Use DataSet.GetChanges() method

What is the use of DataSet.HasChanges() Method? 
DataSet.HasChanges method returns a boolean true if there are any changes made to the DataSet, including new, deleted, or modified rows. This method can be used to update a DataSource only if there are any changes.

How do you roll back all the changes made to a DataSet since it was created? 
Invoke the DataSet.RejectChanges() method to undo or roll back all the changes made to a DataSet since it was created.

What happnes when you invoke RejectChanges method, on a DataSet that contains 3 tables in it? 
RejectChanges() method will be automatically invoked on all the 3 tables in the dataset and any changes that were done will be rolled back for all the 3 tables.

When the DataTable.RejectChanges method is called, any rows that are still in edit-mode cancel their edits. New rows are removed. Modified and deleted rows return back to their original state. The DataRowState for all the modified and deleted rows will be flipped back to unchanged.

What is the DataSet.CaseSensitive property used for? 
When you set the CaseSensitive property of a DataSet to true, string comparisons for all the DataTables within dataset will be case sensitive. By default the CaseSensitive property is false.

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.