what is difference between dataset and table adapter can someone explain with interesting example please.
How does table adapter gets data from sql server ?
You use the DataAdapter
to fill the DataSet
with the data from SqlServer.
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand("SELECT * FROM tbl_tblname", conn);
try
{
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd; // Set the select command for the DataAdapter
da.Fill(ds); // Fill the DataSet with the DataAdapter
DataGridView1.DataSource = ds.Tables[0]; // I just displayed the results in a grid view for simplicity. If Asp.Net you will have to call a DataBind of course.
catch (Exception ex)
{
conn.Close();
conn.Dispose();
}
TableAdapter
is just a strongty typed class that holds anDataAdapter
which holds select-,insert,update- and delete commands. So you can use it to fill a (strongy typed) DataTable/DataSet or to update data. msdn.microsoft.com/en-us/library/bz9tthwx.aspx