如何使用带有帐户限制的Acces2013数据库在VB2010中创建登录表单 [英] How to make a login form in VB2010 using Acces2013 database with account restriction

查看:75
本文介绍了如何使用带有帐户限制的Acces2013数据库在VB2010中创建登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我使用acces数据库登录代码。我需要限制某些帐户查看某种形式。例如,我的系统包含form1-form9。对于普通用户,我想限制它们仅查看form1-form6。可以这样做吗?



这个是gui [ ^ ]

这是数据库 [ ^ ]





 进口 System.Data.OleDb 

公开 Form1

Dim Tempahan_Kayak1DataSet As String

私有 Sub Form1_Load( ByVal sender 作为系统。对象 ByVal e As System.EventArgs)句柄 MyBase .Load
' TODO:这行代码将数据加载到'Tempahan_Kayak1DataSet1.Akaun'表中。您可以根据需要移动或删除它。
.AkaunTableAdapter.Fill( .Tempahan_Kayak1DataSet1.Akaun)

结束 Sub

私有 Sub Button1_Click( ByVal sender As System。 Object ByVal e As System.EventArgs) Handles Button1.Click
Dim connection As OleDbConnection( Provider = Microsoft.ACE.OLEDB.12.0; Data Source = D:\ work\Sem 5 \ Cik Nazri(SE)\Sistem Kanu \\ \\D atabase\Tempahan Kayak1.accdb
Dim 命令 As OleDbCommand( 选择[ID] FROM [Akaun] WHERE [用户名] =用户名和[密码] =密码,连接)
Dim usernameParam As OleDbParameter( username,TextBox1.Text)
Dim passwordParam As OleDbParameter( password,TextBox2.Text)
命令。 Parameters.Add(usernameParam)
command.Parameters.Add(passwordParam)
command.Connection.Open()




Dim reader As OleDbDataReader
reader = command.ExecuteReader

如果 TextBox1.Text = TextBox2.Text = 然后
MsgBox( Sila Masukkan用户名dan Password! Perhatian!
TextBox1.Focus()
否则
如果 reader.HasRows 然后

MsgBox( Selamat Datang ..
.Hide()
Form9.Show()


否则
MsgBox( Sila semak用户名/密码安达!
TextBox1.Text =
TextBox2.Text =
TextBox1.Focus()

结束 如果
结束 如果
command.Connection.Close()


结束 Sub

私有 Sub Button2_Click(< span class =code-keyword > ByVal 发​​件人作为系统。对象 ByVal e As System.EventArgs)句柄 Button2.Click
关闭()

结束 Sub


私有 Sub Label2_Click( ByVal sender 作为系统。对象 ByVal e As System.EventArgs)句柄 Label2.Click

结束 Sub
私有 Sub Label1_Click( ByVal sender As System。 Object ByVal e As System.EventArgs)句柄 Label1.Click

结束 Sub
私有 Sub Label3_Click( ByVal sender As System。对象 ByVal e As System.EventArgs)句柄 Label3.Click

结束 Sub


结束





我使用此代码进行登录,但仍然无效。任何人都可以帮助检查我的源代码,并给我一些关于它的错误的提示

解决方案

是的,它可以完成,但是你没有提供任何关于它的信息你的问题。然而......



我强烈建议你阅读这些文章:

从.NET应用程序访问Microsoft Office数据 [ ^ ]

使用Microsoft Access 2010进行数据编程 [ ^ ]

演练:使用角色管理网站用户 [ ^ ]

ASP.NET授权 [ ^ ]



有些文章与你的问题没有直接关系,但它会帮助你理解你应该做什么。



当你遇到困难时,请回到这里并提出详细的问题,提供有关你的问题的更多信息。

Can anyone help me on a code on login using acces database. And i need to restrict certain account to view certain form. Eg, my system consist on form1-form9. And For normal user i want to restrict them only to view form1-form6. Can this be done?

This is the gui[^]
This is the database[^]


Imports System.Data.OleDb

Public Class Form1

    Dim Tempahan_Kayak1DataSet As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Tempahan_Kayak1DataSet1.Akaun' table. You can move, or remove it, as needed.
        Me.AkaunTableAdapter.Fill(Me.Tempahan_Kayak1DataSet1.Akaun)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connection As New OleDbConnection ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Work\Sem 5\Cik Nazri (SE)\Sistem Kanu\Database\Tempahan Kayak1.accdb")
        Dim command As New OleDbCommand("Select [ID] FROM [Akaun] WHERE [Username] = username AND [Password] = password", connection)
        Dim usernameParam As New OleDbParameter("username", TextBox1.Text)
        Dim passwordParam As New OleDbParameter("password", TextBox2.Text)
        command.Parameters.Add(usernameParam)
        command.Parameters.Add(passwordParam)
        command.Connection.Open()




        Dim reader As OleDbDataReader
        reader = command.ExecuteReader

        If TextBox1.Text = "" Or TextBox2.Text = "" Then
            MsgBox("Sila Masukkan Username dan Password!", "Perhatian!")
            TextBox1.Focus()
        Else
            If reader.HasRows Then

                MsgBox("Selamat Datang..")
                Me.Hide()
                Form9.Show()


            Else
                MsgBox("Sila semak Username/Password Anda!")
                TextBox1.Text = ""
                TextBox2.Text = ""
                TextBox1.Focus()

            End If
        End If
        command.Connection.Close()


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Close()

    End Sub


    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

    End Sub
    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub
    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click

    End Sub


End Class



I use this code for my login but it still doesnt work. Anyone can help check my source code and give me some hint on whats wrong with it

解决方案

Yes, it could be done, but you didn't provide any information about your issue. Nevertheless...

I'd strongly recommend you to read these articles:
Accessing Microsoft Office Data from .NET Applications[^]
Data Programming with Microsoft Access 2010[^]
Walkthrough: Managing Web Site Users with Roles[^]
ASP.NET Authorization[^]

Some articles are not related directly to your "issue", but it would help you to understand what you should do.

When you get stuck, please, come back here and ask detailed question, providing more information about your issue.


这篇关于如何使用带有帐户限制的Acces2013数据库在VB2010中创建登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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