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

Ganeshji
Posted by in ADO.NET category on for Beginner level | Points: 250 | Views : 26966 red flag
Rating: 4.5 out of 5  
 4 vote(s)

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 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 !

 


Page copy protected against web site content infringement by Copyscape

About the Author

Ganeshji
Full Name: Zinnia Sarkar
Member Level:
Member Status: Member
Member Since: 7/24/2010 12:50:40 PM
Country: India
Regards, Ganeshji


Login to vote for this post.

Comments or Responses

Posted by: Mittaikariss on: 11/29/2011 | Points: 25
nice...
Posted by: Ksuresh on: 12/9/2011 | Points: 25
Very good Article....
Posted by: Kamlesh420 on: 12/10/2011 | Points: 25
Very nice article it will help me thanks Ganeshji
Posted by: Ganeshji on: 12/11/2011 | Points: 25
Thanx Mittaikariss, Ksuresh & Kamlesh420. Keep on reading!
Posted by: Bhupentiwari on: 7/9/2012 | Points: 25
Very good article

Login to post response

Comment using Facebook(Author doesn't get notification)