新人学习 求助 什么是列名Admin无效!
数据库里面 就两个字段 用户名 admin 密码 admin
protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e)
{
string user = TextName.Text;
// string pwd = TextPwd.Text;
SqlConnection conn = new SqlConnection("Server=(local);database=OA_info;uid=sa;pwd=000000;");
conn.Open();
SqlCommand cmd = new SqlCommand("select * from Admin_user where UserName="+user, conn);// and UserPwd='+pwd
int cnt=(int)cmd.ExecuteScalar();
if(cnt==1)
{
Response.Redirect("up.aspx");
}
else
{
Response.Redirect("login.aspx");
}
}
解决方案 »
- XMLHttpReq.readyState为空或不是对象,大家帮忙看下啊。急`````
- GridView嵌套RadioButtonList的绑定问题
- @Html.ActionLink 基础
- ado.net实体数据模型 为什么我的vs里面没有这一项,是不是需要安装什么?求详解
- AspNetPager分页格式如何修改,注意:不是样式,是格式
- 求SQL表设计案例!
- 微软到底出vs2005中文正式版本没有?
- 插入页面的问题,控件资源释放
- Index 0 is either negative or above rows count的問題!
- 百度地图添加轨迹问题
- asp.net FileUpload 完整路径[100分]
- 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败
一模一样的?
这里应该是select * from Admin_user where UserName=‘"+user+“’”吧
SqlCommand cmd = new SqlCommand("select * from Admin_user where UserName='"+user+"'", conn);// and UserPwd='+pwd
, conn);//
{
string user = TextName.Text;
string pwd = TextPwd.Text;
SqlConnection conn = new SqlConnection("Server=(local);database=OA_info;uid=sa;pwd=000000;");
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from Admin_user where UserName=@username and UserPwd=@userpwd";
cmd.Parameters.AddWithValue("@username", user);
cmd.Parameters.AddWithValue("@userpwd", pwd);
int cnt=(int)cmd.ExecuteScalar();
if(cnt==1)
{
Response.Redirect("up.aspx");
}
else
{
Response.Redirect("login.aspx");
}
}
改成SqlCommand cmd = new SqlCommand("select * from Admin_user where UserName='"+user+"'", conn)
sql语句中的字符要加引号,要不会被当成列之类的对象处理