3层中的登录代码错误 [英] Login code error in 3-Tier
本文介绍了3层中的登录代码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码出现错误(VS 2010)。错误是{对象引用没有设置为对象的实例。}。然而相同的代码在VS 2008中运行正常。请帮助我。提前致谢。
I am getting error on my code given below(VS 2010). Error is "{"Object reference not set to an instance of an object."}. However the same code runs fine in VS 2008. Please help me. Thanks in advance.
////DAL
public DataTable LoadUserName()
{
DataTable dTable = null;
try
{
con.Open();
String selectStr = "select uCode,uID,uPassword from tUsers";
SqlDataAdapter da = new SqlDataAdapter(selectStr, con);
dTable = new DataTable();
da.Fill(dTable);
con.Close();
}
catch (Exception e)
{
String Str = e.Message;
}
return dTable;
}
///BAL
public bool authenticate(string username, string password)
{
LoginDAL dal = new LoginDAL();
DataTable dTable = dal.LoadUserName();
bool found = false;
foreach (DataRow dRow in dTable.Rows) ///Getting error on this line
{
if ((username == dRow["uID"].ToString()) &&
password == dRow["uPassword"].ToString())
{
userID =Convert.ToInt32(dRow["uCode"].ToString());
found = true;
}
}
if
(!found)
{
return false;
}
return found;
}
推荐答案
这是非常低效的代码。
仅供参考为了解决问题,你的dTable没有行设置断点并看看。
connection.close可能是问题
This is really really inefficient code.
just for the sake of solution, your dTable has no rows set a breakpoint and have a look.
The connection.close might be the problem
这篇关于3层中的登录代码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文