参数化查询时报错,调试时,到:cmd.Parameters.Add(new SqlParameters("UN", username));就提示:SqlParameterCollection 只接受非空的 SqlParameter 类型对象,不接受 SqlParameters 对象。
protected void btnSubmit_Click(object sender, EventArgs e)
{
string username = Request.Form["txtAccounts"];
string password = Request.Form["txtPassword"];
password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5"); using (SqlConnection conn = new SqlConnection("server=192.168.1.8;database=QPGameUserDB;uid=sa;pwd=suncheng;"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select count(*) from AccountsInfo where Accounts=@UN and LogonPass=@PW";
cmd.Parameters.Add(new SqlParameters("UN", username));
cmd.Parameters.Add(new SqlParameters("PW", password));
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
Response.Redirect("/user/indexhome.aspx");
}
else
{
Response.Write("<script>alert('密码或用户名错误!')</script>");
}
}
conn.Close();
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string username = Request.Form["txtAccounts"];
string password = Request.Form["txtPassword"];
password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5"); using (SqlConnection conn = new SqlConnection("server=192.168.1.8;database=QPGameUserDB;uid=sa;pwd=suncheng;"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select count(*) from AccountsInfo where Accounts=@UN and LogonPass=@PW";
cmd.Parameters.Add(new SqlParameters("UN", username));
cmd.Parameters.Add(new SqlParameters("PW", password));
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
Response.Redirect("/user/indexhome.aspx");
}
else
{
Response.Write("<script>alert('密码或用户名错误!')</script>");
}
}
conn.Close();
}
}
解决方案 »
- 还是附件上传的问题 详细说说最好。
- 求一条SQL处理,其他历遍方法(c#)也可以,自己不会,只有问了
- 请问,ASP.NET获取qq好友列表,这样写对吗?
- 關於表單 添加<input type=text>
- asp.net怎么连access数据库啊
- 在asp.net中关于JAVASCRIPT里面写正确表达式的问题,在线等
- 为什么我的web报表插件安装不上呀?(急!急!急!)
- [Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design"是什么意思?
- 需要javascript 调用动态的链接文字
- 如何突出显示关键字?
- WAP
- 关于WF复合活动?
cmd.Parameters.Add(new SqlParameters("@PW", password));
cmd.Parameters.Add(new SqlParameters("@PW", password));我错了,我自己不小心多加了个S在后面