Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
good
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()
        {
            con.Open();
            cmd.Connection = con;
            cmd.CommandText = "select * from Emp";
            da = new SqlDataAdapter(cmd);
            da.Fill(dt);
 
            GridView1.DataSource = dt;
            GridView1.DataBind();
 
            con.Close();
        }
  Permalink  
Rate this: bad
good
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()
    {
        try
        {
                      Cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Cn"].ConnectionString);
            Cn.Open();
                       OnOff = "On";
        }
        catch (Exception ex)
        {
            //MsgBox(ex.Message)
        }
    }
 
 public DataSet GetDs(string Crit)
    {
        DataSet ObjDs = new DataSet();
        try
        {
            Cmd = new SqlCommand(Crit, Cn);
            Cmd.CommandTimeout = 0;
            //Cmd.ExecuteNonQuery()
            Da = new SqlDataAdapter(Cmd);
            Da.Fill(ObjDs);
        }
        catch (Exception ex)
        {
            //MsgBox(ex.Message)
        }
        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");
 
Enjoy...
HAPPY CoDINGSmile | :)
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 7,215
1 DamithSL 5,114
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,747
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2014
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