如何使用MS作为数据库在C#中创建登录 [英] how to creat login In C# using MS as database

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

问题描述

你好,
我使用MS Access创建数据库
包含管理表{adminID,用户类型,用户名,用户密码}
和人员表{staffID,密码.... etc},我想在C#中创建登录表单.
如果用户是admin,则可以登录并可以添加员工的ID并为其输入密码...员工也可以使用其ID和自己的密码登录.

请帮助我遇到错误

hello ,
i created database using MS access
contain Admin table{adminID, usertype, username, userpassword}
and staff table {staffID, password ....etc}, i want to create login form in C#
if the user is admin can login and can add staff''s ID and put a password for them... also the staff can login by their ID and their own password.

please help i''m getting errors

public partial class Form1 : Form
{
     
   private void Button2_Click_1(object sender, EventArgs e)
   {
      this.Close();
   }
   
   private void btnlogin_Click(object sender, EventArgs e)
   {
      OleDbConnection connection = new OleDbConnection(); 
      connection.ConnectionString =@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\sss\Documents\Visual Studio 2010\Projects\eee1\eee1\EMP.accdb;adminId=admin;";
      connection.Open();

      OleDbCommand command = new OleDbCommand("SELECT * FROM Admin", connection); 
      OleDbDataReader reader = command.ExecuteReader(); 
      
      try
      {
         while (reader.Read()) 
         {
            txtuname.ToString();
            txtupass.ToString();

            if (txtuname.Text =="admin" &&txtupass.Text =="admin") 
            {
               this.Hide(); 
               new MainForm().Show();
               break; 
            }
            else
            {
               MessageBox.Show("UserName/Password doesnt exist"); 
               break; 
            }
         }
      }
      catch (Exception err) 
      {
         MessageBox.Show(err.Message); 
      }
      finally
      {
         connection.Close();
         command.Dispose();
         connection.Dispose();
      }
   }
}

推荐答案

找不到可安装的ISAM"

如果是
"Could not find installable ISAM"

In the case of
Provider=Microsoft.Jet.OLEDB.4.0

这通常意味着您将程序作为64位应用程序运行.没有64位版本的Jet OleDB驱动程序,因此您会收到此消息.

尝试更改项目属性以生成32位应用程序-如果问题消失了,那么您需要确定是否更愿意使用Access或64位应用程序!

This normally means that you are running your program as a 64 bit application. There is no 64 bit version of the Jet OleDB drivers, so you get this message.

Try changing your project properties to generate a 32 bit application instead - if the problem goes away, then you need to decide if you are more wedded to Access or 64 bit applications!


而不是定义自定义安全机制,您是否考虑过使用内置的用户级安全性:
Instead of defining a custom security mechanism, have you considered using the built-in user level security: About user-level security (MDB)[^]


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

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