操作数据库test 取view字段内容 如果是1就提示this.AlertScript = "AlertScript('div_name','该用户无法操作');"; 如果不是1就继续
操作数据库test 取kill字段内容 如果有内容就提示this.AlertScript = "AlertScript('div_name','该用户锁定');"; 如果没有内容就继续
操作数据库test 取uid字段内容,取uid2字段内容,然后保存到uid_old字段
谢谢大家。。
public class SQLEDIT : CommonPageBase
{
public string AlertScript = string.Empty;
private string checkcode;
public string msg = string.Empty;
private string name; public bool CheckName(string name)
{
string commandText = "select count(0) from [test] where id=@id";
SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@id", SqlDbType.VarChar, 0x15) };
commandParameters[0].Value = name;
int num = (int) sqlconnet.ExecuteScalar(ConfigurationManager.ConnectionStrings["test"].ConnectionString, CommandType.Text, commandText, commandParameters);
return (num > 0);
} public bool CheckPass(string name, string pass)
{
string commandText = "select count(0) from [test] where id=@id and pass=@pass";
SqlParameter[] commandParameters = new SqlParameter[2];
string str2 = MD5.HashString(pass, Encoding.GetEncoding("GB2312"));
commandParameters[0] = new SqlParameter("@id", SqlDbType.VarChar, 0x15);
commandParameters[0].Value = name;
commandParameters[1] = new SqlParameter("@pass", SqlDbType.VarChar, 0x24);
commandParameters[1].Value = str2;
int num = (int) sqlconnet.ExecuteScalar(ConfigurationManager.ConnectionStrings["test"].ConnectionString, CommandType.Text, commandText, commandParameters);
return (num > 0);
} protected void Page_Load(object sender, EventArgs e)
{
if (base.IsHttpPost)
{
bool flag = true;
this.checkcode = base.Request.Form["txtCode"].ToString();
if (!bmptool.CheckName(base.Request.Form["txtName"]))
{
this.AlertScript = "AlertScript('div_name','用户名格式错误');";
flag = false;
}
else
{
this.name = base.Request.Form["txtName"].ToString();
}
if (!(this.CheckName(base.Request.Form["txtName"].ToString()) || !flag))
{
this.AlertScript = "AlertScript('div_name','用户名不存在');";
flag = false;
}
if (!(bmptool.CheckPassword(base.Request.Form["txtoldPwd"]) || !flag))
{
this.AlertScript = "AlertScript('div_pwd','旧密码格式错误');";
flag = false;
}
if (!(bmptool.CheckPassword(base.Request.Form["txtnewPwd"]) || !flag))
{
this.AlertScript = "AlertScript('div_pwdc','新密码格式错误');";
flag = false;
}
if ((base.Request.Form["txtnewPwd"].ToString() != base.Request.Form["txtnewPwdc"].ToString()) && flag)
{
this.AlertScript = "AlertScript('div_newpwdc','新密码输入不一致');";
flag = false;
}
if (!(this.CheckPass(base.Request.Form["txtName"].ToString(), base.Request.Form["txtoldPwd"].ToString()) || !flag))
{
this.AlertScript = "AlertScript('div_pwd','旧密码与原密码不匹配!');";
flag = false;
}
if ((this.checkcode != base.Request.Cookies["bmpcode"].Value.ToString()) && flag)
{
this.AlertScript = "AlertScript('div_code','验证码错误');";
flag = false;
}
if (flag)
{
if (this.edits(this.name, base.Request.Form["txtnewPwd"].ToString()))
{
this.msg = "RegMsg('密码修改成功!<br>用户名是:" + this.name + "。<br>新密码是:" + base.Request.Form["txtnewPwd"].ToString() + "<br><div class=\"btnp\"><input name=\"btnClose\" value=\"关闭\" type=\"button\" onclick=\"new window.top.Box().Close();\" /></div>');";
}
else
{
this.msg = "RegMsg('修改失败!稍后再修改...<br>关闭窗口');";
}
}
}
} public bool edits(string name, string pass)
{
string commandText = "update [test] set password=@password,pass=@pass where id=@id";
string str2 = MD5.HashString(pass, Encoding.GetEncoding("GB2312"));
SqlParameter[] commandParameters = new SqlParameter[3];
commandParameters[0] = new SqlParameter("@password", SqlDbType.VarChar, 0x24);
commandParameters[0].Value = pass;
commandParameters[1] = new SqlParameter("@pass", SqlDbType.VarChar, 0x24);
commandParameters[1].Value = str2;
commandParameters[2] = new SqlParameter("@id", SqlDbType.VarChar, 0x15);
commandParameters[2].Value = name;
return (sqlconnet.ExecuteNonQuery(ConfigurationManager.ConnectionStrings["test"].ConnectionString, CommandType.Text, commandText, commandParameters) > 0);
}
}
}
操作数据库test 取kill字段内容 如果有内容就提示this.AlertScript = "AlertScript('div_name','该用户锁定');"; 如果没有内容就继续
操作数据库test 取uid字段内容,取uid2字段内容,然后保存到uid_old字段
谢谢大家。。
public class SQLEDIT : CommonPageBase
{
public string AlertScript = string.Empty;
private string checkcode;
public string msg = string.Empty;
private string name; public bool CheckName(string name)
{
string commandText = "select count(0) from [test] where id=@id";
SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@id", SqlDbType.VarChar, 0x15) };
commandParameters[0].Value = name;
int num = (int) sqlconnet.ExecuteScalar(ConfigurationManager.ConnectionStrings["test"].ConnectionString, CommandType.Text, commandText, commandParameters);
return (num > 0);
} public bool CheckPass(string name, string pass)
{
string commandText = "select count(0) from [test] where id=@id and pass=@pass";
SqlParameter[] commandParameters = new SqlParameter[2];
string str2 = MD5.HashString(pass, Encoding.GetEncoding("GB2312"));
commandParameters[0] = new SqlParameter("@id", SqlDbType.VarChar, 0x15);
commandParameters[0].Value = name;
commandParameters[1] = new SqlParameter("@pass", SqlDbType.VarChar, 0x24);
commandParameters[1].Value = str2;
int num = (int) sqlconnet.ExecuteScalar(ConfigurationManager.ConnectionStrings["test"].ConnectionString, CommandType.Text, commandText, commandParameters);
return (num > 0);
} protected void Page_Load(object sender, EventArgs e)
{
if (base.IsHttpPost)
{
bool flag = true;
this.checkcode = base.Request.Form["txtCode"].ToString();
if (!bmptool.CheckName(base.Request.Form["txtName"]))
{
this.AlertScript = "AlertScript('div_name','用户名格式错误');";
flag = false;
}
else
{
this.name = base.Request.Form["txtName"].ToString();
}
if (!(this.CheckName(base.Request.Form["txtName"].ToString()) || !flag))
{
this.AlertScript = "AlertScript('div_name','用户名不存在');";
flag = false;
}
if (!(bmptool.CheckPassword(base.Request.Form["txtoldPwd"]) || !flag))
{
this.AlertScript = "AlertScript('div_pwd','旧密码格式错误');";
flag = false;
}
if (!(bmptool.CheckPassword(base.Request.Form["txtnewPwd"]) || !flag))
{
this.AlertScript = "AlertScript('div_pwdc','新密码格式错误');";
flag = false;
}
if ((base.Request.Form["txtnewPwd"].ToString() != base.Request.Form["txtnewPwdc"].ToString()) && flag)
{
this.AlertScript = "AlertScript('div_newpwdc','新密码输入不一致');";
flag = false;
}
if (!(this.CheckPass(base.Request.Form["txtName"].ToString(), base.Request.Form["txtoldPwd"].ToString()) || !flag))
{
this.AlertScript = "AlertScript('div_pwd','旧密码与原密码不匹配!');";
flag = false;
}
if ((this.checkcode != base.Request.Cookies["bmpcode"].Value.ToString()) && flag)
{
this.AlertScript = "AlertScript('div_code','验证码错误');";
flag = false;
}
if (flag)
{
if (this.edits(this.name, base.Request.Form["txtnewPwd"].ToString()))
{
this.msg = "RegMsg('密码修改成功!<br>用户名是:" + this.name + "。<br>新密码是:" + base.Request.Form["txtnewPwd"].ToString() + "<br><div class=\"btnp\"><input name=\"btnClose\" value=\"关闭\" type=\"button\" onclick=\"new window.top.Box().Close();\" /></div>');";
}
else
{
this.msg = "RegMsg('修改失败!稍后再修改...<br>关闭窗口');";
}
}
}
} public bool edits(string name, string pass)
{
string commandText = "update [test] set password=@password,pass=@pass where id=@id";
string str2 = MD5.HashString(pass, Encoding.GetEncoding("GB2312"));
SqlParameter[] commandParameters = new SqlParameter[3];
commandParameters[0] = new SqlParameter("@password", SqlDbType.VarChar, 0x24);
commandParameters[0].Value = pass;
commandParameters[1] = new SqlParameter("@pass", SqlDbType.VarChar, 0x24);
commandParameters[1].Value = str2;
commandParameters[2] = new SqlParameter("@id", SqlDbType.VarChar, 0x15);
commandParameters[2].Value = name;
return (sqlconnet.ExecuteNonQuery(ConfigurationManager.ConnectionStrings["test"].ConnectionString, CommandType.Text, commandText, commandParameters) > 0);
}
}
}
比如SqlCommand -> MySqlCommand
操作数据库test 取kill字段内容 如果有内容就提示this.AlertScript = "AlertScript('div_name','该用户锁定');"; 如果没有内容就继续
操作数据库test 取uid字段内容,取uid2字段内容,然后保存到uid_old字段 ===
select view,kill,uid,uid2 from test where id=@id
select view,kill,uid,uid2 from test where id=@id and pwd=@pwddatatable dt= ……;
if(dt.rows.count>0)
{
if(dt.rows[0]["view"].tostring()!="")
{
dt=……;
……
}
}
MySqlParameter是MySql的, SqlParameter是MSSql的.
楼主重写了?
一般的把用于MSSql的,把Sql换成MySql就可以用了。
楼主用一下,就能发现规律了
这个有点看不明白,放到哪个位置?
还有
操作数据库test 取uid字段内容,取uid2字段内容,然后保存到uid_old字段
这个我不小心写错了.应该是
取UID字段内容 +uid2字段内容然后保存
select * from [test] where id=@id and pass=@passSqlDataReader dr;
if(dr.Read())
{
string u=dr["uid"].ToString();
//再重新定义SqlCommand cmd2更新数据
}
using (SqlDataReader dr1 = cmd1.ExecuteReader())
{
while (dr1.Read())
{
using(SqlConnection con2 = new SqlConnection(""))
{
SqlCommand cmd2 = new SqlCommand("", con2 );
cmd2.ExecuteNonQuery();
}
}
}
MYSQL使用mysql操作类
case txtName when '1' then 'this.AlertScript="AlertScript(''div_name'',''该用户无法操作'');' end,
case when 'kill'='1' then 'this.AlertScript="AlertScript(''div_name'',''该用户锁定'');' end,
uid,uid2
from a
case txtName when '1' then 'this.AlertScript="AlertScript(''div_name'',''该用户无法操作'');' end,
case when [kill]='1' then 'this.AlertScript="AlertScript(''div_name'',''该用户锁定'');' end,
uid,uid2
from a
我贴了我原有代码,.只是想加两个功能
操作数据库test 取view字段内容 如果是1就提示this.AlertScript = "AlertScript('div_name','该用户无法操作');"; 如果不是1就继续
操作数据库test 取kill字段内容 如果有内容就提示this.AlertScript = "AlertScript('div_name','该用户锁定');"; 如果没有内容就继续
操作数据库test 取uid字段内容,取uid2字段内容,然后UID内容 + UID2内容保存到uid_old字段
http://fs.unpack.cn/web.rar