SQL Data Adapter
SQL 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:-