此采用的是三层架构,BLL,DAL,UI
怎么样才能判断用户名是否存在呢,以下是我初写的代码,发现有错,不知道怎么写,跪求大神
报错信息,Row不存在
怎么样才能获取数据库查询结果呢
Row=0的时候做插入数据
否则弹出对话框
protected void btn_Click(object sender, EventArgs e)
{
string user = txtuser.Text;
DataTable table = BLL.Mgr.exausers(user);
if (Row = 0)
{
Model.USER user = new Model.USER();
try
{
user.user = user.Text;
user.mail = user.Text;
BLL.Login.Saveuser(user);
Response.Write("<script>alert('添加成功!');</script>");
}
catch
{
Response.Write("<script>alert('添加失败!');</script>");
}
}
else
{
Response.Write("<script>alert('此用户名已存在');</script>");
}
}
if (Row = 0) 换成 if(table.Rows.Count==0)
if (Row = 0)
==>
if (table.Rows.Count == 0)
if(table.Rows.Count==0)
{
insert(xxxx)
}
else{
Response.Write("alert('添加数据失败!');");
}
Rows那里你判断的是用户存不存在,如果sql语句可以查出 说明不等于0
等于0说明数据库没有
你要用你的 table 点出Rows,
首先报错信息提示Row不存在的原因是,if(row==0) row这个变量你没有声明,所以不存在。 如果你想这个写 :
第一:
int row = table.Rows.Count;
第二:
if(row==0)
这样就不会报错了。