What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 2312 |  Welcome, Guest!   Register  Login
Home > Articles > ADO.NET > Dataadapter.Fill() Method can be overloaded in 5 different ways.

Dataadapter.Fill() Method can be overloaded in 5 different ways.

4 vote(s)
Rating: 4.5 out of 5
Article posted by Ganeshji on 11/27/2011 | Views: 9331 | Category: ADO.NET | Level: Beginner | Points: 250 red flag


In different ways, dataadapter.Fill() method can be overridden. In this article, i have tried to elaborate this. Here all the 5 different ways has been explained with code and snap shots.

Download


 Download source code for Dataadapter.Fill() Method can be overloaded in 5 different ways.


5 different overloads of Dataadapter.Fill() Method


As i have already stated in the following , link http://www.dotnetfunda.com/articles/article1146-data-adapter-.aspx, that Dataadapter is working just like a bridge between a datasource and dataset. One of the method of Dataadapter is Fill() Method. 
It can be overloaded in 5 different ways. 

Objective


I have tried here to clearly explain, how this Fill() method can be used in 5 different ways.

First Overload

Dataadapter.Fill(ds) here fetches the data from tblMobile and fills in the DataSet ds



Output

On clicking the button Fill DataSet, the dataadapter fills the dataset and finally,  the GridView shows all the records present in the dataset ds.

Second Overload


Here Dataadapter.Fill(dt) fetches records from tblMobile and fills in the datatable named dt.




Output

On clicking the button Fill DataTable, the dataadapter fills the datatable and finally Gridview displays all the records present in the datatable.


Third Overload


Here a datatable named nameOfDataTable has been filled by the dataadapter.Fill() method. As this datatable is within the dataset, we can use the commented line also to fill the gridview. Let me be clear here, 
To set the datasource of the gridview control we can use:

  1. ds.Tables[0]     //valid
  2. ds.Tables["nameOfDataTable"]    //valid

As this is the first table of the dataset, so we can use ds.Tables[0], otherwise we can use the table name to indicate which table i need to access.





Output




Fourth Overload


This overload takes 3 parameters. The types of parameters are int,int and datatable. Here first parameter is the starting record, second parameter is the maximum number of record and the last parameter is the datatable where we have to fill the records. The range from which the records are to be fetched are mentioned here using the parameters.





Output



Fifth Overload


At last, this overload takes 4 parameters. The types of parameters are dataset,int,int,string. The first parameter is the name of the dataset, second parameter is the starting record number, third parameter is the maximum number of records and the last parameter is the name of the table.

At first ds1 is filled with all the records of tblMobile. And then, dataadapter.Fill() method has filled the datatable nm with the specified range of records.




Following figure shows the contents of dataset ds1. It is having all the records of tblMobile.




Now, the dataadapter object da1 takes 4 parameters and fills the datatable named nm with the records of specified range.

Output


Hope this article was useful, thanks

Happy reading !

 


If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:1 year(s)
Home page:
Member since:Saturday, July 24, 2010
Level:Starter
Status: [Member]
Biography:
 Responses
Posted by: Mittaikariss | Posted on: 29 Nov 2011 06:27:05 AM | Points: 25

nice...

Posted by: Ksuresh | Posted on: 09 Dec 2011 08:15:01 AM | Points: 25

Very good Article....

Posted by: Kamlesh420 | Posted on: 10 Dec 2011 06:15:40 AM | Points: 25

Very nice article it will help me thanks Ganeshji

Posted by: Ganeshji | Posted on: 11 Dec 2011 09:01:15 AM | Points: 25

Thanx Mittaikariss, Ksuresh & Kamlesh420. Keep on reading!

Posted by: Bhupentiwari | Posted on: 09 Jul 2012 06:48:29 AM | Points: 25

Very good article

>> Write Response - Respond to this post and get points
Related Posts

This article will give you the overview of how to copy data from one table to another by using ado.net sqlbulkcopy classes.

This is the Part 2 of ADO.NET. In this section we will touch base on one of important concepts in ADO.NET.

In this article, we shall learn how to work with multiple results set using and SqlDataReader.

To efficiently write the code of Data Access Layer we must be aware about the functionality/features of DataSet, SqlDataReader and XmlReader. In this article, I am trying to describe which objects fits in what scenario.

In this article I teach you how you can get hierarchal data using Entity Framewwork with self referencing table

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 8:42:46 PM