62,243
社区成员




<input type="text" id="txtName" value="" runat="server" />
<input type="text" id="txtPass" value="" runat="server" />
/// <summary>
/// 添加用户
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="userPass">用户密码</param>
public static int AddUser(string userName, string userPass)
{
string strSql = "INSERT INTO [User]([userName],[userPass])VALUES(@userName, @userPass)";
SqlParameter[] para = new SqlParameter[] {
new SqlParameter("@userName", SqlHelper.SqlNull(userName)),
new SqlParameter("@userName", SqlHelper.SqlNull(userPass))
};
//调用SqlHelper类的ExecuteNonQuery方法,返回受影响行数
return SqlHelper.ExecuteNonQuery(strSql, CommandType.Text, para);
}
SqlHelper类中SqlNull方法
public static object SqlNull(object obj)
{
if (obj == null)
{
return DBNull.Value;
}
else
{
return obj
}
}