CODEDIGEST
Home » Articles
Search
 

Technologies
 

Sponsored links
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
ADO.Net 2.0 Features – Part 1

By Satheesh babu
Posted On Jun 22,2008
Article Rating:
Be first to rate
this article.
No of Comments: 5
Category: ADO.Net
Print this article.

ADO.Net 2.0 Features – Part 1

DataTableReader Object and SqlBulkCopy object

 

.Netframework 2.0 introduced many new features which made .net programming easy and feature rich. In this series of article, we will understand some of the new classes and features that the 2.0 framework provides for the developers. This part we will understand DataTableReader Object and SqlBulkCopy object in detail.

 

DataTableReader Object

DataTableReader is similar to DataReader class available in ADO.net 1.x. As we all know, DataReader object can read single row of data from the database in a connected mode. In the same way, DataTableReader can be used to read data from a DataTable or DataSet object. The CreateDataReader() method in DataTable object exposes the DataTableReader object to loop through into the DataTable.

 

DataTableReader dtdr = dt.CreateDataReader();

 

Where dt is the DataTable.

 

Usage

The usage will be similar to DataReader object.

To loop through,

 

DataTableReader dtdr = dt.CreateDataReader();       

        while (dtdr.Read())

        {

            Response.Write(dtdr[0].ToString()+"<br>");

        }

 

Copying DataTable to another using DataTableReader

DataTable.Load() method will accept DataTableReader object as argument and does the job for us.

 

Usage

//Copy one dt to another

        DataTable finaldt = new DataTable();

        finaldt.Load(dt.CreateDataReader());

        dtdr = finaldt.CreateDataReader();

 




SqlBulkCopy for bulk copy
This is a yet another wonder that is packed with ADO.net 2.0 called SqlBulkCopy class.

 

Purpose

This class can be used for performing bulk copy of data from one table to another table in same database server or different server similar to DTS and bcp utility. It can also be used to bulk copy from sqlserver 2005 database table to sql server 2000 database table, keeping in mind that destination table will have all the columns matching with the one we are copying from the source.

 

Advantages

It results in good performance compared to insert scripts. Take a look at the post in the reference section which compares the performance between insert script and SqlBulkCopy class.

 

Restrictions

This object can be used only with SqlServer as destination database table.

 

Implementation

Overloads

SqlBulkCopy.WriteToServer (DataRow[]) 

Copies all rows from the supplied DataRow array to a destination table specified by the DestinationTableName property of the SqlBulkCopy object. 

 

SqlBulkCopy.WriteToServer (DataTable) 

Copies all rows in the supplied DataTable to a destination table specified by the DestinationTableName property of the SqlBulkCopy object. 

 

SqlBulkCopy.WriteToServer (IDataReader

Copies all rows in the supplied IDataReader to a destination table specified by the DestinationTableName property of the SqlBulkCopy object. 

 

SqlBulkCopy.WriteToServer (DataTable, DataRowState) 

Copies only rows that match the supplied row state in the supplied DataTable to a destination table specified by the DestinationTableName property of the SqlBulkCopy object. 

 

SqlBulkCopy in Action

string connectionString = "Data Source=BABULIVES;Initial Catalog=tempdb;Integrated Security=True";

       

        using (SqlConnection sourceConnection =

                   new SqlConnection("Data Source=BABULIVES;Initial Catalog=NorthWind;Integrated Security=True"))

        {

            sourceConnection.Open();

              using (SqlConnection destinationConnection =

                           new SqlConnection(connectionString))

                      {

                     destinationConnection.Open();

              

                     using (SqlBulkCopy bulkCopy =

                                      new SqlBulkCopy(destinationConnection))

                            {

                            bulkCopy.DestinationTableName = "dbo.Employees";

 

                            try

                            {

                      

                                   bulkCopy.WriteToServer(reader);

                             }

                            catch (Exception ex)

                             {

                                   Response.Write(ex.Message);

                             }

                            finally

                             {

                       

                                    reader.Close();

                             }

                     }

 

                    }

       }     

 

Reference

SqlBulkCopy Performance Comparison

 

Conclusion

Thus, we have understood 2 new great objects that are packed with .Netframework 2.0. Moving forward we will see other features of ADO.Net 2.0 in the forth coming articles.

Happy Coding!!

Similar Articles
You can contribute to CodeDiget.Com:
Donate to CodeDigest.com
Article Feedback
Comments
That's an ingelliten
That's an ingellitent answer to a difficult question xxx http://reqkxwlchlm.com [url=http://hjbskgfoks.com]hjbskgfoks[/url] [link=http://oogqacmtb.com]oogqacmtb[/link]
? ? ? ... ? ?
? ? ? ... ? ? ?? ?? ? ... ?? ?? ?? ? ? ? ? ?? ? ? ? ? ?? ? ?? ? ? ? ? ... ))??? ? ? ? ? ? ?? ? ? ? ? ? ? ? ... ?? ? ? ? ? ? ? ? ? ? ? ... ? ? ? ? ? ? ?? ?? ? ? ? ?? ?? ... ? ? ?? ?? ?... ? ?? .. ? ? ? ? ? ? ? ? ? ?? ...???... ? ? ?? ? ? ? ? ?? ? ?? ? ? ? ? ? ?? ... ? ? ? ? ? ??? ... ? ??? ? ? ? ? ? ? ?? ?? ? ? ? ? ... :-P? ? ? ? ?? ... ? ? ? ? ? ? ? ??? ? ... ? ?? ? ? ?? ? ??? ? ? ? ? ? ? ? ? ? ? ? ? ...Hmoo... Thanks. Sometimes people have to stand alone to prove that they can still stand... Be <a href="http://bggkpvjk.com">storng</a>..!!! ? ? ... ?? ? ? ? ? ... ))? ? ... ? ? ? ? ? ? ? ? ? ?? ? ... ? ?? ?? ? ? ?? ... ) ? ? ... ? ? ? .. ? ? ? ?? ? ? ? ?? ? ? ?? ? ? ? ? ? ?? ? ...? ? ... ? ?? ? ? ? ? ? ?? ... ?? ? ? ? ? ? ? ? ??? ? ? ? ... )? ? ?? ... ? ? ??? ?? ? ?? ? ? ? ??? ? ? ? ? ? .. ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ?? ?? ... )?? ?? ... ? ? ? ? ?? ? ? ? ?? ? ?? ??? ??? ?? ?? ? ? ? ? ?? ? ? ?? ... ? ? ... ?... ? ?? .. ? ?? ... ?? ? ? ? ? ? ? ? ? ?? ? ? ? ? ?? ? ? ?? ? ? ? ... ))?? ... ?? ?... ? ? ? ? ??? ... ( ? ? ? ?? ? ? ?? ? ? ? ...) ? ? ? ... ? ? ? ? ? ? ? ? ... ??? ?? ? ? ? ?? ? ?? ?? ? ?? ... ? ? ?... ? ? ? ?? ? ? ? ? ? ? ? ?? ? ? ? ?? ? ?? ...
??????
?????? ???????HTML??:<a> <abbr> <acronym> <b> <blockquote> <cite> <code> <del> <em> <i> <q> <strike> <strong> var RecaptchaOptions = { theme : 'blackglass', lang : 'en' , tabindex : 5 }; #submit {display:none;} http://qlmzkzl.com [url=http://nuiynvpg.com]nuiynvpg[/url] [link=http://fcujqhh.com]fcujqhh[/link]
So does means the SP
So does means the SP1 will contain the MVC and<a href="http://bkwyrdwtqs.com"> ettniy</a> framework also? Due to my environment installed .NET Framework 3.5 SP1(beta) due to SQL 2008, and the ASP.NET Extension preview won't recognize it and installation failed.
Please try like this
Please try like this, Removing Set Items If setItemList.Count > 0 Then For Each items As String In setItemList set the PrimaryKey property for the DataTable oebjct Dim myPrimaryKey(1) As DataColumn myPrimaryKey(0) = setDetailsDT.Columns( SetID ) setDetailsDT.PrimaryKey = myPrimaryKey use the Find() method to locate the DataRow Dim myRemoveDataRow As DataRow = setDetailsDT.Rows.Find(items) myRemoveDataRow.Delete() setDetailsDT.AcceptChanges() Next End If