调用方法的灵异事件

moonwrite 2008-05-25 03:46:23
我自己写的一个类 灵异事件发生在:public bool userIsExist(User user) 方法和 public bool blogNameIsExist(User user) 灵异情况看调用

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// User 的摘要说明
/// </summary>
public class User
{
public string strName;
public string strPwd;
public string strSex;
public string strEmail;
public string strBlogName;
public string strBlogType;
public SqlConnection conn = DataBase.createDBconn();

public User()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

public bool isSave(User user)
{
try
{
if ((userIsExist(user)&&blogNameIsExist(user)))
{
conn.Open();
string strSql = "insert into userTable(userName,userPwd,sex,Email,blogName,blogType)";
strSql += " values('" + user.strName + "','" + user.strPwd + "','" + user.strSex + "','" + user.strEmail + "','" + user.strBlogName + "','" + user.strBlogType + "')";

SqlCommand sqlCommand = new SqlCommand(strSql, conn);
sqlCommand.ExecuteNonQuery();


conn.Close();

return true;
}
else
{
return false;
}



}
catch (Exception)
{
conn.Close();
return false;
}
}

public bool userIsExist(User user)
{
try
{
conn.Open();
string strSql = "select count(*) from userTable where (userName like '" + user.strName + "')";
SqlCommand sqlCommand = new SqlCommand(strSql, conn);
int exist = (int)sqlCommand.ExecuteScalar();

if (exist > 0)
{
return true;
}
else
{
return false;
}


conn.Close();
}
catch (Exception)
{
conn.Close();
return false;
}


}

public bool blogNameIsExist(User user)
{
try
{
conn.Open();
string strSql = "select count(*) from userTable where (blogName like '" + user.strBlogName + "')";
SqlCommand sqlCommand = new SqlCommand(strSql, conn);
int exist = (int)sqlCommand.ExecuteScalar();

if (exist > 0)
{
return true;
}
else
{
return false;
}


conn.Close();
}
catch (Exception)
{
conn.Close();
return false;

}

}

public bool checkUser(User user)
{
try
{
conn.Open();
string strSql = "select count(*) from userTable where (userName like '" + user.strName + "' and userPwd like '" + user.strPwd + "')";
SqlCommand sqlCommand = new SqlCommand(strSql, conn);
int exist = (int)sqlCommand.ExecuteScalar();

if (exist > 0)
{
return true;
}
else
{
return false;
}


conn.Close();
}
catch (Exception)
{
conn.Close();
return false;
}

}

}

在一个用户控件中的调用
protected void btnSubmit_Click(object sender, EventArgs e)
{
User user = new User();
user.strName = this.txtUserName.Value;
user.strPwd = this.txtUserPwd.Text;
if (this.rdoBoy.Checked)
{
user.strSex = "男";
}
else
{
user.strSex = "女";
}
user.strEmail = this.txtEmail.Text;
user.strBlogName = this.txtBlogName.Value;
user.strBlogType = this.ddlBlogType.Text;

以下是问题的关键(单独使用是指 下面两句只选一句调用 而不是分开 既然分开调用 后面也总是false)
//Response.Write(user.userIsExist(user).ToString());//单独使用能正确返回 true or false
//Response.Write(user.blogNameIsExist(user).ToString()); 单独使用能正确返回 true or false

如果一起调用的话
//Response.Write("用户"+user.userIsExist(user).ToString() + "博客名"+user.blogNameIsExist(user).ToString()); //判断用户是否存在能正确返回true or false 判断博客名是否存在总是返回 false
把他们调换位置
//Response.Write("博客名"+user.blogNameIsExist(user).ToString() + "用户"+user.userIsExist(user).ToString() ); //判断博客名是否存在能正确返回true or false 判断用户是否存在总是返回 false

}

谢谢


...全文
64 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
magicworks 2008-05-27
  • 打赏
  • 举报
回复
第一,我没有发现save的调用在用户控件中
第二,判断userIsExist怎么能用like ?
第三,the same as blogNameIsExist ?

不知道是不是真正的原因

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧