使用SQL数据库的C#中的登录系统 [英] Login System in c# with sql database

查看:86
本文介绍了使用SQL数据库的C#中的登录系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个包含2个表单的登录系统,第1个表单具有2个文本框用户名和密码,第2个表单具有2个标签....它与数据库连接,该数据库包含2个表,其中1个用于用户名和密码,而2table具有名称和phone#和两个表都与forgein键相关...........我希望该用户提供他的用户名和密码,并且其名称和phone#在那些标签中以另一种形式出现. ................. plz帮助我plz

i make a login sytem which is included 2 form 1st form have 2text box username and password and 2nd from have 2 labels .... its is connected with database which included 2 tables 1 for username and password and 2table have name and phone# and both table are in relationship with forgein key...........i want that user give his user name and password and its name and phone# see in another form in those label which are there ...................plz help me plz

推荐答案

当用户登录并且是有效用户然后存储在此处属于user_id.然后重定向到下一页,并在第2页的page_load上编写以下代码

when user is login and he is valid user then store there user_id in sesstion. then redirect to next page and on page_load of page 2 write the following code

Protected void Page_Load()
{
   If(Session["YourSessionName"] != null && Session["YourSessionName"] != "")
   {
      int userID = Convert.ToInt32(Session["YourSessionName"]);
      If(!IsPostBack)
        {
           // fetch the data from database and set the Text property of your label here
        }
   }
}



添加了代码格式.



Code formatting added.


您需要将用户名和密码从1Form传递到2Form
前任.在表格1
创建2Form对象并传递用户名和密码
You need to pass Username and Password from 1Form to 2Form
Ex. In Form 1
Create object of 2Form and pass UserName and Password
Form2 f = new Form(Username,Password);
     f.show();



在Form 2中,创建具有两个参数的构造函数,即Username和Password



In Form 2 create Constructor that have two parameter ie Username and Password

string UserName="";
   string Password="";
   Public Form2(string UserName, string Password)
   {
        this.UseName = UserName;
        this.Password = Password;
        InitializeComponent();
   }



此外,在Form2中的加载事件在查询之后运行,但两个表中都必须有一个唯一的整数



Also, In Form2 Load Event Run Following Query BUT MUST HAVE ONE UNIQUE CLOUMN IN BOTH TABLE

SELECT T1.USERNAME,T1.PASSWORD ,T2.NAME, T2.PHONE FROM TABLE1 T1 INNERJOIN TABLE2 T2 ON T1.ID = T2.ID WHERE T1.USERNAME="" AND T1.PASSWORD="";



根据您的要求更新上述查询

希望对您有所帮助

添加了代码格式.



Update above Query as per u r requirement

I hope this will be help for u

code formatting added.


这篇关于使用SQL数据库的C#中的登录系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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