潘
潘安
Unregistered / Unconfirmed
GUEST, unregistred 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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string strconn = ConfigurationSettings.AppSettings["dsn"];
SqlConnection cn = new SqlConnection(strconn);
cn.Open();
string strsql = "
select * from Users where 用户名=' "
+ TextBox1.Text + "
'and 密码=' "
+ TextBox2.Text + "
' ";
SqlCommand cm = new SqlCommand(strsql, cn);
try
{
SqlDataReader dr = cm.ExecuteReader();
if (dr.Read())
{
Session["userid"] = dr["用户名"];
Session["user_power"] = dr["权限"];
if ((int)Session["user_power"] == 0)
{
Response.Redirect("query.aspx"
}
else
{
Response.Redirect("student.aspx"
}
}
else
{
Label3.Text = "用户名或密码错误,登陆失败!";
}
cn.Close();
}
catch (Exception ee)
{
Response.Write(ee.ToString());
}
}
}
在我这个系统中学生的权限为:0.管理人员的权限为:1.上面的代码功能是根据输入的用户名和密码确定登陆者的权限从而登陆不同的界面
运行时总是提示-->"SqlDataReader dr = cm.ExecuteReader();"这段代码出错!我想了好久都不知它出错在哪里,哪位高手帮帮忙呀
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string strconn = ConfigurationSettings.AppSettings["dsn"];
SqlConnection cn = new SqlConnection(strconn);
cn.Open();
string strsql = "
select * from Users where 用户名=' "
+ TextBox1.Text + "
'and 密码=' "
+ TextBox2.Text + "
' ";
SqlCommand cm = new SqlCommand(strsql, cn);
try
{
SqlDataReader dr = cm.ExecuteReader();
if (dr.Read())
{
Session["userid"] = dr["用户名"];
Session["user_power"] = dr["权限"];
if ((int)Session["user_power"] == 0)
{
Response.Redirect("query.aspx"
}
else
{
Response.Redirect("student.aspx"
}
}
else
{
Label3.Text = "用户名或密码错误,登陆失败!";
}
cn.Close();
}
catch (Exception ee)
{
Response.Write(ee.ToString());
}
}
}
在我这个系统中学生的权限为:0.管理人员的权限为:1.上面的代码功能是根据输入的用户名和密码确定登陆者的权限从而登陆不同的界面
运行时总是提示-->"SqlDataReader dr = cm.ExecuteReader();"这段代码出错!我想了好久都不知它出错在哪里,哪位高手帮帮忙呀