The C# language supports the following clauses that you can use in a query:
. From: - Enables you to specify the data source and a variable for iterating over the data source (a range variable).
. Where: - Enables you to filter the results of a query.
. Select: - Enables you to specify the items included in the results of the query.
. Group: - Enables you to group related values by a common key.
. Into: - Enables you to store the results of a group or join into a temporary variable.
. Orderby: - Enables you to order query results in ascending or descending order.
. Join: - Enables you to join two data sources using a common key.
. Let: - Enables you to create a temporary variable to represent sub query results.
System.linq.enumerable Class in SDK documentations view full list of method:-
. Aggregate ():-Enables you to apply a function to every item in a sequence.
. Average ():-Returns the average value of every item in a sequence.
. Count ():-Returns the count of items from a sequence.
. Distinct ():-Returns distinct items from a sequence.
. Max ():-Returns the maximum value from a sequence.
. Min ():-Returns the minimum value from a sequence.
. Select ():-Returns certain items or properties from a sequence.
. Single ():-Returns a single value from a sequence.
. Skip ():-Enables you to skip a certain number of items in a sequence and return theremaining elements.
. Take ():-Enables you to return a certain number of elements from a sequence.
. Where ():-Enables you to filter the elements in a sequence.
Creating Custom AJAX Controls and Behaviors:-
Creating AJAX Controls in the Ajax world, an AJAX control is the equivalent of an ASP.NET control. However, whereas an ASP.NET control executes on the server and renders content to the browser, an AJAX control executes entirely in the browser. An AJAX control is built entirely from JavaScript and DOM elements.
When using Visual Web Developer, you create an AJAX control by selecting the menu option Website, Add New Item and selecting the AJAX Client Control template.
Of all the new features introduced in.NET Framework. Summary 3.5, LINQ to SQL is the most significant one. It might represent the biggest change in the way to application interact with database.
Understanding Automatic Properties:-
When working with LINQ to SQL, you often use classes to represent nothing more than the list of columns you want to retrieve from the database (the shape of the data) like the select list in a SQL query. In those cases, you just want to do the minimum amount of work possible to create a list of properties, and automatic properties allow you to do this.
Understanding LINQ:-
LINQ stand for language integrated query. LINQ consist of set of new language feature added both c# and VB.Net language that enable to perform the queries. LINQ enables you to use SQL query like syntax within c# or VB.Net.
The ADO.NET Framework encompasses a huge number of classes. However, at its heart, it really consists of the following three classes:
. Connection enables you to represent a connection to a data source.
. Command enables you to execute a command against a data source.
. DataReader enables you to represent data retrieved from a data source.
The different implementations of the Connection, Command, and DataReader classes are grouped into the following namespaces:
. System.Data.SqlClient Contains ADO.NET classes for connecting to Microsoft SQL Server version 7.0 or higher.
. System.Data.OleDb Contains ADO.NET classes for connecting to a data source with an OLEDB provider.
. System.Data.Odbc Contains ADO.NET classes for connecting to a data source with an ODBC driver.
. System.Data.OracleClientContainsADO.NET classes for connecting to an Oracle database (requires Oracle 8i Release 3/8.1.7 Client or later).
. System.Data.SqlServerCe Contains ADO.NET classes for connecting to SQL Server Mobile.
ADO.NET follows the Provider model all implementations of the Connection, Command, and DataReader classes inherit from a set of base classes. Here is a list of these base classes:
. DbConnection: - The base class for all Connection classes.
. DbCommand: - The base class for all Command classes.
. DbDataReader: - The base class for all DataReader classes.
Under the covers, the SqlDataSource control uses ADO.NET objects such as the ADO.NET DataSet, DataReader, Parameter, and Command objects to interact with a database. In particular, any ASP.NET Parameter objects that you declare when working with the SqlDataSource control get converted into ADO.NET Parameter objects.
In some cases, you will want to work directly with these ADO.NET Parameter objects when using the SqlDataSource control. For example, you might want to add additional ADO.NET parameters programmatically before executing a command.
Executing Insert, Update, and Delete Commands:-
The SqlDataSource control has methods that correspond to each of the different types of commands that it represents:
. Delete enables you to execute a SQL delete command.
. Insert enables you to execute a SQL insert command.
. Select enables you to execute a SQL select command.
. Update enables you to execute a SQL update command.
Executing Select Commands:-
The procedure for executing a select command is different from executing insert, update, and delete commands because a select command returns data. How you can execute the SqlDataSource controls Select () method programmatically and represent the data that the method returns.
Remember that a SqlDataSource control can return either a DataView or DataReader depending on the value of its DataSourceMode property. The SqlDataSource controls Select () method returns an object of type IEnumerable. Both DataViews and DataReaders implement the IEnumerable interface.
You can cancel SqlDataSource commands when some criterion is not met. For example,
You might want to validate the parameters that you are using with the command before executing the command. You can cancel a command by handling any of the following events exposed by the SqlDataSource control:
. Deleting Happens immediately before the SqlDataSource executes its delete command.
. Filtering Happens immediately before the SqlDataSource filters its data.
. Inserting Happens immediately before the SqlDataSource executes its insert command.
. Selecting Happens immediately before the SqlDataSource executes its select command.
. Updating Happens immediately before the SqlDataSource executes its delete command.
You aren’t required to use the SqlDataSource control only when working with DataBound controls. You can create parameters and execute the commands represented by a SqlDataSource control by working directly with the properties and methods of the SqlDataSource control in your code.
The SqlDataSource control can be used to represent four different types of SQL commands. The control supports the following four properties:
SelectCommand
InsertCommand
UpdateCommand
DeleteCommand
Executing Stored Procedures
The SqlDataSource control can represent SQL stored procedures just as easily as it can represent inline SQL commands. You can indicate that a command represents a stored procedure by assigning the value StoredProcedure to any of the following properties:
SelectCommandType
InsertCommandType
UpdateCommandType
DeleteCommandType
Handling SQL Command Execution Errors:-
Whenever you build a software application you need to plan for failure. Databases go down, users enter unexpected values in form fields, and networks get clogged. It is miraculous that the Internet works at all. You can handle errors thrown by the SqlDataSource control by handling any or all of the following four events:
. Deleted Happens immediately after the SqlDataSource executes its delete command.
. Inserted Happens immediately after the SqlDataSource executes its insert command.
. Selected Happens immediately after the SqlDataSource executes its select command.
. Updated Happens immediately after the SqlDataSource executes its delete command.
By default, the SqlDataSource control is configured to connect to Microsoft SQL Server version 7.0 or higher. The default provider used by the SqlDataSource control is the ADO.NET provider for Microsoft SQL Server.
We represent a database connection string with the SqlDataSource controls ConnectionString property.
Connecting to Other Databases:-
If you need to connect to any database server other than Microsoft SQL Server, then you need to modify the SqlDataSource control Provider Name property.
The .NET Framework includes the following providers:
.System.Data.OracleClient Use the ADO.NET provider for Oracle when connecting to an Oracle database.
.System.Data.OleDb Use the OLE DB provider when connecting to a data source that supports an OLE DB provider.
. System.Data.Odbc Use the ODBCprovider when connecting to a data source with an ODBC driver.
Storing the connection string in the web.config file:-
Storing connection strings in your pages is a bad idea for three reasons. First, it is not a good practice from the perspective of security. In theory, no one should ever be able to view the source code of your ASP.NET pages. In practice, however, hackers have discovered security flaws in the ASP.NET framework. To sleep better at night, you should store your connection strings in a separate file.
Also adding a connection string to every page makes it difficult to manage a website. If you ever need change password then you changed every page that contain it.
If, on the other hand you store the connection in one file you can update the password by modifying just one file.
Finally, storing a connection string in a page can, potentially, hurt the performance of your application. The ADO.NET provider for SQL Server automatically uses connection pooling to improve your applications data access performance. Instead of being destroyed when they are closed, the connections are kept alive so that they can be put back into service quickly when the need arises. However, only connections that are created with the same connection strings are pooled together (an exact character-by-character match is made). Adding the same connection string to multiple pages is a recipe for defeating the benefits of connection pooling.
The tabular DataBound controls are the main set of controls that you use when working with database data. These controls enable you to display and, in some cases; modify data retrieved from a database or other type of data source. There are six tabular DataBound controls. These controls can be divided in to two types: those that display multiple data items at a time and those that display a single data item at a time. First, you can use any of the following controls to display a set of data items:
1) GridView Displays set of data items in an HTML table. For example, you can use the GridView control to display all the records contained in the Movies database table. This control enables you to display, sort, page, select, and edit data.
2) DataList displays a set of data items in an HTML table. Unlike the GridView control, more than one data item can be displayed in a single row.
3) Repeater displays a set of data items using a template. Unlike the GridView and DataList controls, a Repeater control does not automatically render an HTML table.
4) ListView Displays a set of data items using a template. Unlike the Repeater control, the ListView control supports sorting, paging, and editing database data.
You can dynamically load a User control at runtime and display it in a page. Imagine, for example, that you want to display different featured products randomly on the home page of your website. However, you want to display each featured product with a completely different layout. In that case, you can create a separate User control for each product and load one of the User controls randomly at runtime.
Using DataBound Controls:-
You use DataBound controls to generate your applications user interface for working with data. The DataBound controls can be used to display and edit database data, XML data, or just about any other type of data you can imagine. There are three main types of DataBound controls: listcontrols, tabular DataBound controls, and hierarchical DataBound controls.
Working with List Controls:-
Listcontrols are used to display simple option lists. The ASP.NET 3.5 Framework includes the following five Listcontrols:
1) BulletedListDisplays: - A bulleted list of items. Each item can be displayed as
text, a link button, or a hyperlink.
2) CheckBoxList Displays list of check boxes. Multiple check boxes in the list can be selected.
3) DropDownList Displays a drop-down list. Only one item in the drop-down list can be selected.
4) ListBox Displays list box. You can configure this control so that only one item
in the list can be selected or multiple items can be selected.
5) RadioButtonList Displays a list of radio buttons. Only one radio button can be
Displaying information: - Using the label control.
Using literal control. Is similar to label control also use for display HTML contents on browser.
Submitting For Data:-
Asp.net includes 3 control you can use to submit a form to the server the button, Linkbutton and Imagebutton control. Three have same function but distinct appearance.
Using Rich Control:-
We examine a more specialized set of control known collectively as a rich control.
Displaying Multi-part of Form:-
We can use multiview control to divide large form into several sub-forms.
Following commands recognize multiview control.
1. NextView: - The multiview to activate the next view control.
2. PrevView: - The multiview to activate the previous view control.
3. SwitchViewById: - The multiview to activate the view specified by the button control command arguments.
4. SwitchViewByIndex: - The multiview activates the view specified by the button control command arguments.
Ajax and User Control:-
AJAX (Asynchronous Javascript and XML) enables you updates the contents in page without posing the page back to the server. Behind the scenes, AJAX uses the XMLHttp ActiveX component or the XMLHttpRequest intrinsic browser object.