使用Access数据库登录 [英] Login using Access Database

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

问题描述

现在有一个登录系统,它没有使用数据库,但在项目中编写了一些数据,非常小而简单,看起来像这样。

Now there is a logon system at the present which is not using a database, but some data programed in the project, very small and simple, it looks like this.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Access
{
    public partial class Login : Form
    {
        string username = "admin";
        string password = "admin";


        public Login()
        {
            InitializeComponent();
        }

        private void txtExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnEnter_Click(object sender, EventArgs e)
        {
            if (txtUserNm.Text == username && txtPassWrd.Text == password)
            {
                RecordDB rdb = new RecordDB();
                rdb.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("Incorrect Username or Password ! Please try again !");
            }
        }
    }
}





现在你要问,什么是probelm?没有问题,它太简单了。当使用它时,它让位于主程序,用于插入存储在MS Access 2010数据库中的upadating删除数据。在此数据库中,主程序连接到TPersons表。现在我已经创建了一个名为TAdminPW的新表(管理员密码表)

现在我想要做的是使用TAdminPW表连接到同一数据库的samll登录程序并使用(用户)存储在那里的名字或传递词。



所以首先我需要用DataBase声明一个连接字符串,然后使用SQL语句只读取(用户名/密码字)并比较它们是相同的,如果是这样,用户可以登录否则显示错误。这是正确的逻辑,如果是这样,以上所有内容都将被更改仍然可以重用一些结构吗?



Now You are going to ask, what is the probelm ? There is no problem, its too simple. when using this it gives way to main program for inserting upadating removeing Data which is stored in an MS Access 2010 Database. In this Database the main program connects to a TPersons Table. Now I have made a new table called TAdminPW ( Table for Admin Pass Words)
now what I want to do is that samll Login program to connect to the same database using the TAdminPW Table and use the (user names or pass words) stored in there.

So at first I need to declare a connetion string with DataBase, and then use an SQL Statement to only Read (user name / pass words) and compare them if they are the same, if so user can login otherwise show error. Is this the correct logic, if so the all the above will be changed of still I can reuse some structure ?

推荐答案

请阅读本教程:从.NET应用程序访问Microsoft Office数据 [ ^ ]。这对于开始就足够了。
Please, read this tutorial: Accessing Microsoft Office Data from .NET Applications[^]. It would be enough for start.


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

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