0% found this document useful (0 votes)
58 views

SQL Data Adapter

Data adapters link datasets to databases by filling datasets with data retrieved from database tables using queries. The SqlDataAdapter class has a Fill method that executes a SelectCommand query, gets the result set, and copies it to a data table object within the dataset. Datasets provide a disconnected mechanism for managing data and contain data tables, which represent logical tables with rows, columns, keys, and relations. Data tables can now be used directly without datasets for loading data using a data reader from a query result.

Uploaded by

Rajesh Vhadlure
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

SQL Data Adapter

Data adapters link datasets to databases by filling datasets with data retrieved from database tables using queries. The SqlDataAdapter class has a Fill method that executes a SelectCommand query, gets the result set, and copies it to a data table object within the dataset. Datasets provide a disconnected mechanism for managing data and contain data tables, which represent logical tables with rows, columns, keys, and relations. Data tables can now be used directly without datasets for loading data using a data reader from a query result.

Uploaded by

Rajesh Vhadlure
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Data Adapter:-

Datasets store a copy of data from the database tables. However, Datasets cannot directly
retrieve data from Databases. DataAdapters are used to link Databases with DataSets. The
SqlDataAdapter class also provides a method called Fill. Calling the Fill method
automatically executes the command provided in the SelectCommand property, receives
the result set, and copies it to a DataTable object.
Program
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string strinsert="select * from authors";
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog =
pubs;Integrated Security=True");
con.Open();
SqlDataAdapter da = new SqlDataAdapter(strinsert,con);
DataSet ds = new DataSet();
da.Fill(ds,"authors");
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
DataSet and Datatable:-

DataSet class is the most commonly used part of ADO.NET in database-driven


applications. This class provides mechanisms for managing data when it is
disconnected from the data source. This capability to handle data in a disconnected
state. The current 2.0 version of ADO.NET retains all the features of its predecessors
and provides a few newer, much-needed features an object created from the DataSet
class works as a container for other objects that are created from the DataTable
class. The DataTable object represents a logical table in memory. It contains rows,
columns, primary keys, constraints, and relations with other DataTable objects.
However, the previous versions of ADO.NET didn’t allow you to work directly with
the DataTable object for some very important tasks, such as reading and writing
data. This limitation required you to always use the DataSet object to perform any
operation on a DataTable. The current version of ADO.NET removes this limitation
and enables you to work directly with the DataTable. The current version of
ADO.NET provides the capability to load a DataTable in memory by consuming a
data source using a DataReader.
Program
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection("Data Source=.; Initial
Catalog =pubs; Integrated Security=True");
string query = "SELECT * FROM authors";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}

You might also like