Ado.net 2.0

26 10 2007

Connection Pooling Enhancements

ADO.NET 1.0 introduced a new infrastructure for pooling database connections. The Microsoft SqlClient and OracleClient data providers use this infrastructure; the OleDb and Odbc data providers do not. The new pooling mechanism provided granular support of connection pooling parameters, including minimum and maximum pool sizes and the ability for the pool manager to wait for a user-defined amount of time for a connection to become available in the pool. ADO.NET adds a connection-pooling enhancement that allows you to programmatically “drain” the connection pool; that is, close all of the connections currently kept alive by the pooler. You can clear a specific connection pool by using the static (shared in Visual Basic .NET) method SqlConnection.ClearPool or clear all of the connection pools in an appdomain by using the SqlConnection.ClearPools method. Both SqlClient and OracleClient implement this functionality.





Top 10 New Features in ADO.NET 2.0

26 10 2007

This article summarizes the new and updated features of ADO.NET 2.0, which ships with .NET Framework 2.0. In my following articles I will discuss these features in more details with sample examples.

Here is a list of new and updated additions to ADO.NET:

1. Bulk Copy Operation

Bulk copying of data from a data source to another data source is a new feature added to ADO.NET 2.0. Bulk copy classes provides the fastest way to transfer set of data from once source to the other. Each ADO.NET data provider provides bulk copy classes. For example, in SQL .NET data provider, the bulk copy operation is handled by SqlBulkCopy class, which can read a DataSet, DataTable, DataReader, or XML objects. Read more about Bulk Copy here.

2. Batch Update

Batch update can provide a huge improvement in the performance by making just one round trip to the server for multiple batch updates, instead of several trips if the database server supports the batch update feature. The UpdateBatchSize property provides the number of rows to be updated in a batch. This value can be set up to the limit of decimal.

3. Data Paging

Now command object has a new execute method called ExecutePageReader. This method takes three parameters – CommandBehavior, startIndex, and pageSize. So if you want to get rows from 101 – 200, you can simply call this method with start index as 101 and page size as 100.

4. Connection Details

Now you can get more details about a connection by setting Connection’s StatisticsEnabled property to True. The Connection object provides two new methods – RetrieveStatistics and ResetStatistics. The RetrieveStatistics method returns a HashTable object filled with the information about the connection such as data transferred, user details, curser details, buffer information and transactions.

5. DataSet.RemotingFormat Property

When DataSet.RemotingFormat is set to binary, the DataSet is serialized in binary format instead of XML tagged format, which improves the performance of serialization and deserialization operations significantly.

6. DataTable’s Load and Save Methods

In previous version of ADO.NET, only DataSet had Load and Save methods. The Load method can load data from objects such as XML into a DataSet object and Save method saves the data to a persistent media. Now DataTable also supports these two methods.

You can also load a DataReader object into a DataTable by using the Load method.

7. New Data Controls

In Toolbox, you will see these new controls – DataGridView, DataConnector, and DataNavigator. See Figure 1. Now using these controls, you can provide navigation (paging) support to the data in data bound controls.

Data Bound Controls

Figure 1. Data bound controls.

8. DbProvidersFactories Class

This class provides a list of available data providers on a machine. You can use this class and its members to find out the best suited data provider for your database when writing a database independent applications.

9. Customized Data Provider

By providing the factory classes now ADO.NET extends its support to custom data provider. Now you don’t have to write a data provider dependent code. You use the base classes of data provider and let the connection string does the trick for you.

10. DataReader’s New Execute Methods

Now command object supports more execute methods. Besides old ExecuteNonQuery, ExecuteReader, ExecuteScaler, and ExecuteXmlReader, the new execute methods are ExecutePageReader, ExecuteResultSet, and ExecuteRow. Figure 2 shows all of the execute methods supported by the command object in ADO.NET 2.0.
Data Reader New Execute Methods

Figure 2. Command’s Execute methods.

Summary

ADO.NET 2.0 provides many new and improved features for developers to improve the performance and reduce the code. In this article, I discussed top 10 features of ADO.NET 2.0. In my forthcoming articles, I will be discussing these features in more details.





Databind Expressions in asp.net 2.0

26 10 2007

In asp.net 2.0 3 types of Databind Expressions are there

1)Eval

2)Bind

3)Function(Customized)

1)Eval:- It is bind the data only in one way means it get the data from datasource and bind the controls that it any modification or update are occur in that control it cant send back to backend

Syntax:- <%#Eval(“columnname”)%>

2)Bind :-It is bind the data in two way

Syntax:- <%#Bind(“ColumnName”)%>

3)Functions:- By write function in code behind bind the data

Syntax:-<%#FunctionName(Eval(“ColumnName”))%>

Example :-<%#F1(Eval(“Job_ID”)%>

public string F1(object args)

{

//some code

}





How to Set Focus on Controls in Asp.net web forms at page level

26 10 2007

In Asp.net 1.1, focus of asp.net controls in web forms by using java script write code but asp.net 2.0 you can set focus on controls at control level and page level.

Control Level means Textbox have one property SetFocus by using this property you can set focus

of cusor in textbox

Page level:-This is another alternative to set the focus on controls

Syntax:-

<form id=”formname” runat=”server” defaultfocus=”controlname”>

</form>

Example:-

<form id=”form1″ runat=”server” defaultfocus=”txtEno”>

<asp:TextBox runat=”server” id=”txtEno”></asp:TextBox>

</form>





ASP.NET 2.0 – Enter Key – Default Submit Button

13 10 2007

One of the most annoying things in developing web pages is handling the “Enter key” for form submission. Enter key has been the favourite way users like to submit forms. Though we provide Buttons to click on, the easiest and intuitive way is that, I can enter some text, make some changes and then hit “Enter” to accomplish my submission.

“Enter” Key is handled in a little tricky way by uplevel browsers like Internet Explorer, when it comes to ASP.NET.

  • If there is a single Textbox and single button, then it becomes straight forward, the button is submitted. However, the event code doesnt get executed, though the page postsback.
  • If there are two or more, buttons, then it takes up the first button as the default button. However, it still doesnt execute the event handler but just refreshes the page.

You can supress the Enter key event using Javascript. But this would result in other undesirable effects like, any Enter key in the form i.e. within Text Area or basically where large text is entered, would be disabled.

The earlier work around was to associate a javascript function to each Button to verify the that the relevant button is submitted upon Enter key.

ASP.NET 2.0 introduces a wonderful work around for this. By simply specifying the “defaultbutton” property to the ID of the <asp:Button>, whose event you want to fire, your job is done.

The defaultbutton property can be specified at the Form level in the form tag as well as at panel level in the <asp:panel> definition tag. The form level setting is overridden when specified at the panel level, for those controls that are inside the panel.

Also, the Event Handler for the specified button, fires thereby simulating a true submit button functionality.

The following sample code contains a form and 4 panels with each of them containing different buttons. It can be noticed that for each panel, there is a default button specified which would trigger the corresponding button’s event handler when “Enter” Key is pressed upon a text changed event.

<form id=”form1″ runat=”server” defaultbutton=”btn1″>

<div>

<asp:TextBox ID=”txt” runat=”server”></asp:TextBox>

<asp:Button ID=”Button5″ runat=”server” Text=”Cancel” OnClick=”Button5_Click” />

<asp:Button ID=”btn1″ runat=”server” Text=”Submit” OnClick=”btn1_Click” />

<asp:Panel ID=”pnl1″ runat=”server” defaultbutton=”Button1″>

<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>

<asp:TextBox ID=”TextBox2″ runat=”server”></asp:TextBox>

<asp:Button ID=”Button1″ runat=”server” Text=”Button1″ OnClick=”Button1_Click” />

</asp:Panel>

<asp:Panel ID=”Panel1″ runat=”server” defaultbutton=”Button2″>

<asp:TextBox ID=”TextBox3″ runat=”server”></asp:TextBox>

<asp:TextBox ID=”TextBox4″ runat=”server”></asp:TextBox>

<asp:Button ID=”Button2″ runat=”server” Text=”Button2″ OnClick=”Button2_Click” />

</asp:Panel>


<asp:Panel ID=”Panel2″ runat=”server” defaultbutton=”Button3″>


<asp:TextBox ID=”TextBox5″ runat=”server”></asp:TextBox>

<asp:TextBox ID=”TextBox6″ runat=”server”></asp:TextBox>

<asp:Button ID=”Button3″ runat=”server” Text=”Button3″ OnClick=”Button3_Click” />

</asp:Panel>

<asp:Panel ID=”Panel3″ runat=”server” defaultbutton=”Button4″>

<asp:TextBox ID=”TextBox7″ runat=”server”></asp:TextBox>

<asp:TextBox ID=”TextBox8″ runat=”server”></asp:TextBox>

<asp:Button ID=”Button4″ runat=”server” Text=”Button4″ OnClick=”Button4_Click” />

</asp:Panel>

</div>

</form>

The corresponding, sample events for the button clicks are


protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(Button1.Text);
}


protected void Button2_Click(object sender, EventArgs e)
{
Response.Write(Button2.Text);
}

protected void Button3_Click(object sender, EventArgs e)
{
Response.Write(Button3.Text);
}

protected void Button4_Click(object sender, EventArgs e)
{
Response.Write(Button4.Text);
}

protected void btn1_Click(object sender, EventArgs e)
{
Response.Write(btn1.Text);
}

protected void Button5_Click(object sender, EventArgs e)
{
Response.Write(Button5.Text);
}

Once we execute the above functionality, we can notice, the corresponding Buttons’ text are displayed when the Enter key is pressed from within a panel and at the form level, it fires the btn1 Button’s event.

This would be a very useful feature in scenarios where we have different sections of the page and would like to have Enter key fire corresponding submit button events





LINQ

12 10 2007

Linq means Language Integrated Query, which is introduced by microsoft in .net 3.5

Linq Sample are:-http://msdn2.microsoft.com/hi-in/vcsharp/aa336746.aspx





Validation

11 10 2007

In Asp.net 2.0 Microsoft provides 5 validation Controls it reaches maximum validation in your web apps but if you want more validation try this peter blum validation controls it is compatible with asp.net 2.0 the link is www.peterblum.com/VAM





Ado.net 2.0

11 10 2007

In Ado.net 2.0 microsoft introduced Factories Classes, in ado.net 1.x microsoft provides some providers by using that providers we can intract specific database only but now ado.net 2.0 by using single class (Factories classes) we can intract with more than one databases





Difference between Server.Transfer and Response.Redirect???

10 10 2007

1)Server.Transfer is work only for asp.net pages only

But Response.Redirect is work both asp.net and html pages

2)Server .Trasfer is used get method

But response.redirect is used both get and post methods

3)By using server.trasfer browser history is not updated

response.redirect is browser history is updated

4)server .transfer round trip is not occur

but response.redirect is occur

5)server.transfer user browser url is not updated

but response.redirect is user browser url is updated





Some Placements Address

10 10 2007

Neo Solutions
Flat No. 301, Siddhardha Rama Krishna Apts.,
Saradhi Studio Lane
Yellareddyguda,
Ameerpet,
Hyderabad 500082
Phone : (040) 66828000 / 65577666
Web : www.neosolutionsonline.com
email : info@neosolutionsonline.com