Click here to Skip to main content
12,821,674 members (35,956 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# C#4.0
kindly tell me in detail about the data set and data adapter and data fill method...
i know the concept of the data set and data adapter and data fill method but still its getting confused.
can u tell me how it works with simple code and explanation.
Posted 5-Dec-12 20:36pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

SqlConnection con = new SqlConnection(@"");
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter da = new SqlDataAdapter();
        DataTable dt = new DataTable();

        public void dataBind()
            cmd.Connection = con;
            cmd.CommandText = "select * from Emp";
            da = new SqlDataAdapter(cmd);

            GridView1.DataSource = dt;

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

public class CommClass
    SqlDataAdapter Da;
    DataSet Ds;
    DataTable Dt;
    SqlCommand Cmd;
    SqlConnection Cn;
    SqlConnection CnW;
    SqlDataReader Dr;
    string OnOff;

    public CommClass()
                      Cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Cn"].ConnectionString);
                       OnOff = "On";
        catch (Exception ex)

 public DataSet GetDs(string Crit)
        DataSet ObjDs = new DataSet();
            Cmd = new SqlCommand(Crit, Cn);
            Cmd.CommandTimeout = 0;
            Da = new SqlDataAdapter(Cmd);
        catch (Exception ex)
        return ObjDs;

this Code is in common class in App_Code..
First of all declare Your all variables in common class
then in constructor make connection(with connctionstring which is in web.config
then in get ds method
(This is what You want to learn)
create new dataset,new command in which You can pass query,connection
than new dataadapter andin that pass command(which have query and connection already!!!)
so You can Fill ds
and return ds
in You aspx.cs
page You have To just write
CommClass objCls=new CommClass();
ds=objCls.GetDs("Select * from EmployeeMst");


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100