0

what is difference between dataset and table adapter can someone explain with interesting example please.

How does table adapter gets data from sql server ?

4
  • This is too vague and too broad for this site. You need to look for a tutorial.
    – H H
    Aug 19, 2013 at 15:04
  • what kind of tutorial sir Aug 19, 2013 at 15:05
  • 1
    A TableAdapter is just a strongty typed class that holds an DataAdapter 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 Aug 19, 2013 at 15:05
  • Like this
    – H H
    Aug 19, 2013 at 15:06

1 Answer 1

2

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();
}
1
  • 1
    Tables[0] might not be tbl_tblname as you assumed. Jul 20, 2015 at 15:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.