Click here to Skip to main content
15,566,065 members
Articles / Programming Languages / C#
Posted 20 Sep 2012

Tagged as


12 bookmarked

Five different overloads of the DataAdapter.Fill() method

Rate me:
Please Sign up or sign in to vote.
4.75/5 (8 votes)
20 Sep 2012CPOL2 min read
A look into the five different overloads of the DataAdapter.Fill() method.


The SqlDataAdapter serves as a bridge between a DataSet and SQL Server for retrieving and saving data. The SqlDataAdapter provides this bridge by mapping Fill, which changes the data in the DataSet to match the data in the data source, and Update, which changes the data in the data source to match the data in the DataSet, using the appropriate Transact-SQL statements against the data source. The update is performed on a by-row basis. For every inserted, modified, and deleted row, the Update method determines the type of change that has been performed on it (Insert, Update, or Delete). Depending on the type of change, the Insert, Update, or Delete command template executes to propagate the modified row to the data source. When the SqlDataAdapter fills a DataSet, it creates the necessary tables and columns for the returned data if they do not already exist. However, primary key information is not included in the implicitly created schema unless the MissingSchemaAction property is set to AddWithKey. You may also have the SqlDataAdapter create the schema of the DataSet, including primary key information, before filling it with data using FillSchema. For more information, see Adding Existing Constraints to a DataSet (ADO.NET).

SqlDataAdapter is used in conjunction with SqlConnection and SqlCommand to increase performance when connecting to a SQL Server database.

The SqlDataAdapter also includes the SelectCommand, InsertCommand, DeleteCommand, UpdateCommand, and TableMappings properties to facilitate the loading and updating of data.

When an instance of SqlDataAdapter is created, the read/write properties are set to initial values. For a list of these values, see the SqlDataAdapter constructor.

The InsertCommand, DeleteCommand, and UpdateCommand are generic templates that are automatically filled with individual values from every modified row through the parameters mechanism.

Step 1

First Overload

DataAdapter.Fill (ds) here fetches the data from User and fills in the DataSet ds.

Image 1


Image 2

Step 2

Second Overload

Here DataAdapter.Fill (dt) fetches records from Users and fills in the DataTable named dt.

Image 3


Image 4

Step 3

Third Overload

Here a datatable named User has been filled by the DataAdapter.Fill () method.

Image 5


Image 6

Step 4

Fourth Overload

This overload takes three 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 ranges from which the records are to be fetched are mentioned here using the parameters.

Image 7


Image 8

Step 5

Fifth Overload

At last, this overload takes four parameters. The types of parameters are DataTable, 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 ds is filled with all the records of Users. And then, DataAdapter.Fill () method has filled the DataTable nm with the specified range of records.

Image 9


Image 10


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Comments and Discussions

QuestionBug Pin
CAKAta1-Jun-18 1:33
CAKAta1-Jun-18 1:33 
Questiondataadapter Pin
Member 1017436329-Oct-13 1:35
Member 1017436329-Oct-13 1:35 
GeneralMy vote of 4 Pin
Florin Bombeanu16-Oct-12 21:23
Florin Bombeanu16-Oct-12 21:23 
Questionon this article Pin
Manohar_manu21-Sep-12 19:24
Manohar_manu21-Sep-12 19:24 
GeneralMy vote of 5 Pin
Manohar_manu21-Sep-12 19:23
Manohar_manu21-Sep-12 19:23 
Generalthanks Pin
Lohithmys8621-Sep-12 7:38
professionalLohithmys8621-Sep-12 7:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.