Click here to Skip to main content
Click here to Skip to main content
Go to top

Five different overloads of the DataAdapter.Fill() method

, 20 Sep 2012
Rate this:
Please Sign up or sign in to vote.
A look into the five different overloads of the DataAdapter.Fill() method.

Introduction

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.

Output

Step 2

Second Overload

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

Output

Step 3

Third Overload

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

Output

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.

Output

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.

Output

License

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

Share

About the Author

Ravindra T C
Software Developer L&T IES Mysore
India India
I'm a software developer. I spent most of the time in learning new technologies. I've a keen interest in client-side technologies especially JavaScript and Jquery it is the most beautiful language ever seen.

I like sharing my knowledge and written some non-popular articles. I believe in quality and standards but blames myself for lagging them.

I believe in small things and they makes me happy!

Comments and Discussions

 
Questiondataadapter PinmemberMember 1017436329-Oct-13 0:35 
GeneralMy vote of 4 PinmemberFlorin Bombeanu16-Oct-12 20:23 
Questionon this article PingroupManohar_manu21-Sep-12 18:24 
thank u so much sir.it ll help sure
GeneralMy vote of 5 PingroupManohar_manu21-Sep-12 18:23 
Generalthanks PinmemberLohithmys8621-Sep-12 6:38 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 20 Sep 2012
Article Copyright 2012 by Ravindra T C
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid