Click here to Skip to main content
15,896,457 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Iam creating a login page but iam confused about using DataReader or DataSet?
Please tell me which one is used generally?

Thanx for Help !!!
Posted
Comments
Sergey Alexandrovich Kryukov 29-May-12 15:37pm    
There is no "generally", it depends.
--SA

Read this[^] and then figure out which is appropriate to your needs.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-May-12 15:38pm    
Nice short article, can server for the introduction into the problem, my 5.
--SA
Ashish_CS 30-May-12 10:56am    
Thank you..useful article..
El_Codero 30-May-12 19:29pm    
A 5+ Link, thanks.
Depends - they do different things.

A DataReader is a forward only, snapshot of a subset of a database table. It is returned as soon as a record is available (though you may have to wait for the next one)
A DataSet uses a DataReader internally to fill itself, and is only returned when the set is completely filled.

If you are doing a login, then I would use a DataReader: you only want a single record, or to know it doesn't exist. You don't need the added (internal) complexity that a DataSet provides.

I use a DataSet (or a DataTable) when I want to display results easily, or serialize them but a DataReader when I am only interested in a single record or a small number of records.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-May-12 15:42pm    
Yes, a 5.
--SA
Ashish_CS 30-May-12 10:57am    
Thank You..
El_Codero 30-May-12 19:29pm    
important point, my 5!
According to me you should use Data reader.
It is easy to handle and fast access

Sample Code :
C#
//retrive Row from Uuer table If username match.
SqlDataReader dr = login.Get_DataReader("select *from users where uname = '" + txtunm.Text + "'");
        try
        {
            //Try read first row if username does not match then generate exception
            dr.Read();
            //Check user Block/Unblock Status
            if (dr["block"].ToString() == "n")
            {
                //Matching password which enter in TextBox
                if (txtpass.Text == dr["pwd"].ToString())
                {
                    Session["unm"] = dr["Name"];
                    Session["UId"] = dr["UId"];
                    Response.Redirect("home.aspx");
                }
                else
                {
                    lblerr.Text = "Invalid Username or password !!";
                }
            }
            else
            {
                lblerr.Text = "You are Blocked By iTPO team, Contact T&P Cell";
            }


All the Best
 
Share this answer
 
Comments
Ashish_CS 30-May-12 10:58am    
Thanx Ya..I got my answer..:)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900