Answer» - A DataAdapter is used to access DATA from a data source by functioning as a bridge between DataSet and a data source. DataAdapter class includes an SQL command set and a database connection. It is helpful to fill the DataSet and resolve changes to the data source.
- The DataAdapter will make use of the Connection object that belongs to the .NET Framework data provider for connecting with a data source. Along with that, it will also use Command objects to RETRIEVE data from the data source as well as to resolve changes to the data source.
- DataAdapter properties that permit the user to control the database are the Select command, Update command, Insert command, and Delete command.
- Example code for the usage of DataAdapter:
using System; using System.Data.SqlClient; using System.Data; namespace DataAdapterExample { public partial class DataAdapterDemo : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { using (SqlConnection conn = NEW SqlConnection("data source=.; database=items; integrated security=SSPI")) { SqlDataAdapter da = new SqlDataAdapter("Select * from items", conn); DataSet s = new DataSet(); da.Fill(s); GridView1.DataSource = s; GridView1.DataBind(); } } } } Here, DataAdapter will receive the data from the items table and fill the DataSet, which will be later used to display the information retrieved from the items database.
|