DS
DS
DS
NET
Data Set in ASP.NET
ASP.NET dataset is a collection of data tables which
contained the data. Dataset is used to fetch the data
without interacting with any data source.
The DataSet represents a subset of the database in memory.
ADO.NET DataSet is a collection of data tables that
contains the relational data in memory in tabular format.
It does not require a continuous open or active connection
to the database.
The DataSet is based on the disconnected architecture.
It is used to fetch the data without interacting with any data
source.
Dataset is the local copy of your database which exists in
the local system and makes the application execute
faster and reliable.
It works like a real database with an entire set of data
which includes the constraints, relationship among
tables, and so on.
The ADO.NET DataSet class is the core component for
providing data access in a distributed and disconnected
environment.
The ADO.NET DataSet class belongs to
the System.Data namespace.
It is nothing but the in-memory data store and at one
time it was holding more than one table. We can also
use asp.net dataset to write and read the data from
documents of XML.
SqlDataAdaptor
The data adaptor object of SqlAdapter class in
ASP.NET allows to populate the dataset in data tables.
The data adapter fill method is used to populate the
data in the dataset.
Dataset in ASP.NET contains the columns, primary
key, rows, data table object relations and constraints.
How to Use Data Set
Setup and declare the connection string
Build and declare the connection string
Create the SQL data adapter object
Fill in the data and create the dataset object
Bind the dataset with the DataGridView
Data Set
protected void Page_Load(object sender, EventArgs e)
{
string connString;
connString = "Data Source=localhost\\SQL2014;Initial
Catalog=doeacc_accr;User ID=sa;Password=meenu123;";
SqlConnection con = new SqlConnection(connString);
con.Open();
Response.Write("Connection Made");
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
SqlDataAdapter ad = new SqlDataAdapter();
String sql = "";
sql = "Select state_code,state_name from
g_state_codes";
ad = new SqlDataAdapter(sql, con);
ad.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string varStateName = ds.Tables[0].Rows[0].ToString()
}
1. Build up Connection String
To use the dataset in our application first step is to set
up the connection string.
This task will be declared and instantiates the
connection with the database.
A connection string is needed when we have accessed
the database server.
The sql connection class is used to connect the
MSSQL server database.
2. Build and Declare the string of query
All the query statement which was used in the
specified program which was declared in this step.
3. Create Sql Data Adaptor Object
The data adapter is basically used to retrieve the data
from the database server. Data adapter is nothing but
the connector class which sat between disconnected
and the connected parts.
Basically, the data adapter class is instantiated with
the new constructor.
4. Fill the account data and create data set
object
Fill the data set with Fill
5. Attach Data set to Data GridView
The data set is attached to the GridView