如何在网站上制作登录页面? [英] how to make login page in website?

查看:122
本文介绍了如何在网站上制作登录页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(@"Data Source=ABHINAV-PC\ABHI;Initial Catalog=Onlineexam;Integrated Security=True");
        con.Open();
        string cmd = "select * from Login where Institute='"+DropDownList1.Text+"'And Username='"+TextBox2.Text+"' and Password='"+TextBox3.Text+"'";
        SqlDataAdapter da = new SqlDataAdapter(cmd, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        if ((ds.Tables[0].Rows.Count > 0))
        {
            Response.Redirect("Exam.aspx");
        }
        else {
            lblloginError.Text = "Username or password must be wrong"; 
        }
        
        
    }



我在做错了什么?

它没有重定向到考试页面...它直接显示错误文本...请帮忙!


What i'm doing wrong in this?
its not redirecting to the exam page...it is directly showing the error text...please help!

推荐答案

 con.Open();
                SqlCommand cmd = new SqlCommand("select * from Login where Institute='"+DropDownList1.Text+"'And Username='"+TextBox2.Text+"' and Password='"+TextBox3.Text+"'", con);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        Response.Redirect("Exam.aspx");


                    }
                }
 else {
            lblloginError.Text = "Username or password must be wrong"; 
        }
con.Close();





尝试这样它会起作用;)



try like this it will work ;)


无法用这些信息直接回答您的问题。你可以自己找到解决方案。

在下面的行之后放置断点并运行程序

can't tell direct answer to your question with these information. you can find the solution by your self.
put break point just after below line and run the program
string cmd = "select * from Login where Institute='"+DropDownList1.Text+"'And Username='"+TextBox2.Text+"' and Password='"+TextBox3.Text+"'";



检查调试时得到的cmd的值。你有什么价值作为学院,用户名和密码?如果没有,你需要找到为什么你没有得到预期的价值。

如果所有这些值都正确则可以复制sql语句并直接在sql server management studio上运行,并确认是否有生成sql的记录。

希望这可以帮助您找到问题所在,然后您可以自行解决或更新具体细节的问题。


$ b以下$ b是改进代码的一些附注:

1. 使用sql参数 [ ^ ]

2. 使用阻止设置连接


这篇关于如何在网站上制作登录页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆