我的登录页面无法连接到Sqldatabase.帮助修改代码. [英] my Login page cannot connect to Sqldatabase. Help modify code.

查看:97
本文介绍了我的登录页面无法连接到Sqldatabase.帮助修改代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string constr = ConfigurationManager.ConnectionStrings["MyConnection"].ToString();
 
        SqlConnection conn = new SqlConnection(constr);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
 
SqlDataSource ads = new SqlDataSource();
 

  ads.SelectParameters.Add("UserName", this.TextBox1.Text);
  ads.SelectParameters.Add("Password", this.TextBox2.Text);
 
 ads.SelectCommand = "SELECT * FROM [Users] WHERE [UserName]= @UserName AND[Password] = @Password";
 
  //retrieve required data
   
 DataView dv = (DataView)ads.Select(DataSourceSelectArguments.Empty);
 
    //diplay error message if record is not found
     if (dv.Count == 0)
        {
 
   this.Label1.ForeColor = System.Drawing.Color.Red;
   this.Label1.Text = "Login failed. The username or password you have entered isn't valid";
            return;
        }
 
        //create Session variables
        this.Session["Username"] = dv[0].Row["Username"].ToString();
        this.Session["UserType"] = dv[0].Row["UserType"].ToString();
 
        //Redirect to respective page based on user 

             if (this.Session["UserType"].ToString().Equals("patient"))
                Response.Redirect("Patient.aspx");
 

            else if (this.Session["UserType"].ToString().Equals("doctors"))
            Response.Redirect("Doctor.aspx");
 

            else if (this.Session["UserType"].ToString().Equals("nurse"))
            Response.Redirect("Nurse.aspx");

推荐答案

您在
在那里,您也没有澄清问题,在这里,您的问题陈述也不清楚.请放心,除非您以清晰,完整的方式提出问题,否则您将不会得到答复.只是将问题次数提出并不能给您任何答案.

如果要重新设计问题,则只需对其进行更新,请勿重新发布.
现在告诉CodeProject,您面临什么错误... ??
You posted the same question at Having a problem to connect different users when user logs in my Login page. I am using sqlconnection...toto my website,
There as well you did not clarify your problem, here as well your problem statement is not clear. Be assured you will not get the response until and unless you present the question in a clear and complete manner. Just putting the question number of times will not get you any answer.

If want to re-frame the question then just update it, do not repost it.
Now tell CodeProject, what error you are facing....?


这篇关于我的登录页面无法连接到Sqldatabase.帮助修改代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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