dataReader或DataSet [英] dataReader or DataSet
本文介绍了dataReader或DataSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个登录页面,但是我对使用DataReader或DataSet很困惑?
请告诉我一般使用哪一个?
Thanx求助!!!
Iam creating a login page but iam confused about using DataReader or DataSet?
Please tell me which one is used generally?
Thanx for Help !!!
推荐答案
阅读这个 [ ^ ]然后找出哪个适合您的需求。
Read this[^] and then figure out which is appropriate to your needs.
取决于 - 他们做不同的事情。
DataReader是数据库表子集的前向快照。一旦记录可用就会返回它(尽管您可能需要等待下一个记录)
DataSet在内部使用DataReader来填充它自己,并且仅在集合完全填充时返回。
如果您正在登录,那么我会使用DataReader:您只需要一条记录,或者知道它不存在。您不需要DataSet提供的额外(内部)复杂性。
当我想轻松显示结果时,我使用DataSet(或DataTable),当我只对单个记录或少量记录感兴趣时,或者将它们序列化为DataReader。
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.
根据我的说法你应该使用数据阅读器。
它易于操作和快速访问
示例代码:
According to me you should use Data reader.
It is easy to handle and fast access
Sample Code :
//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
这篇关于dataReader或DataSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文