谁能帮我看看下面的C#登陆代码有何问题?

来源:百度知道 编辑:UC知道 时间:2024/06/04 00:57:20
protected void btn_login_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=da9c304b579e4cf.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\MSTMS_Data.MDF;Integrated Security=True;User Instance=True");
conn.Open();
string strsql= "select user_power from user where user_id='"+txt_user_id.Text+"'and user_password='"+txt_user_password.Text+"'";
SqlCommand comm = new SqlCommand(strsql, conn);
SqlDataReader datareader = comm.ExecuteReader();
if (datareader.Read())
{
Session["user_id"] = datareader["user_id"];
Session["user_power"] = datareader["user_power"];
if ((int)Session["user_power"] == 0)
{
Response.Redirect("~/Educational Administration/u

你这代码我看的有点乱,你最好是把一些可以简化的代码简化来看,下面这是我的代码,希望对你有帮助(绝对可以运行的);

我这个不是连的数据库,是连的数据文件,其实都差不多,ZhuCe_DataConnectionString这是数据源连接(SqlDataSource)的名字,Teacher是表名,可能是各人写的不同,我看我的感觉好一些^-^
protected void Button3_Click(object sender, EventArgs e)
{
string sUid = TextBox1.Text;
string sPwd = TextBox2.Text;

if (sUid == "" || sPwd == "")
{
Response.Write(@"<script>alert('用户名或密码不能为空');window.location.href='Default.aspx';</script>");
}
else
{
string strcon = ConfigurationManager.ConnectionStrings["ZhuCe_DataConnectionString"].ConnectionString;
con = new SqlConnection(strcon);
SqlCommand sc = new SqlCommand("select count(*) from Teacher where Name=@Name and PassWord=@PassWord", con);
sc.Parameters.Add(new SqlParameter("@Nam