Click here to Skip to main content
Click here to Skip to main content

Five different overloads of the DataAdapter.Fill() method

By , 20 Sep 2012
 

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)

About the Author

Ravindra T C
Software Developer Marlabs Software Pvt Ltd, Mysore
India India
Member
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!

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 4memberFlorin Bombeanu16 Oct '12 - 20:23 
I always like to see different methods for doing the same thing. For begginers this is useful as they tend to learn one method and blindly use it without ever suspecting there are other ways to do it.
Good job!
Questionon this articlegroupManohar_manu21 Sep '12 - 18:24 
thank u so much sir.it ll help sure
GeneralMy vote of 5groupManohar_manu21 Sep '12 - 18:23 
thanks sir.nice article
GeneralthanksmemberLohithmys8621 Sep '12 - 6:38 
Thank you so much sir...

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 20 Sep 2012
Article Copyright 2012 by Ravindra T C
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid