首页 \ 问答 \ 'UserRole'未声明。('UserRole' is not declared. It may be inaccessible due to its protection level)

'UserRole'未声明。('UserRole' is not declared. It may be inaccessible due to its protection level)

我使用VB.NET和microsoft访问作为我的数据库,我是VB.NET的新手,我试图根据当前角色制作不同的访问级别。例如,登录后,Admin将进入主页面。用户登录后,会将其定向到其他页面。 我已经在我的数据库中设置了不同的角色,我在网上发现了一些编码来帮助我

但是我继续收到错误'UserRole'没有声明。 由于其保护级别,它可能无法访问。 我需要先声明UserRole吗? 如果是的话,我该怎么做? 任何帮助将不胜感激,谢谢:)

公共类Form1 Dim loginerror As String Dim UserRole As String公共函数login()Dim DBconn As New ADODB.Connection Dim user as New ADODB.Recordset

    Dim Username As String
    Dim userDB As String
    Dim passDB As String

    Dim UserFound As Boolean

    DBconn.Open("Provider = Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source = '" & Application.StartupPath & "\LoginDB.mdb'")

    user.Open("UserTable", DBconn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

    UserFound = False
    login = False
    Username = "Username = '" & txtuser.Text & "'" '

    Do
        user.Find(Username)
        If user.BOF = False And user.EOF = False Then
            userDB = user.Fields("Username").Value.ToString

            passDB = user.Fields("Password").Value.ToString

            If userDB <> txtuser.Text Then
                user.MoveNext()
            Else
                UserFound = True
                If passDB = txtpass.Text Then
                    UserRole = user.Fields("roles").Value.ToString
                    user.Close()
                    DBconn.Close()
                    Return True
                Else
                    loginerror = "Invalid Password"
                    user.Close()
                    DBconn.Close()
                    Return False
                End If
            End If
        Else
            loginerror = "Invalid Username"
            user.Close()
            DBconn.Close()
            Return False
        End If
    Loop Until UserFound = True
    user.Close()
    DBconn.Close()
    Return False


End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If login() = True And UserRole = "admin" Then
        adminwelcome.Show()
        Me.Close()
    ElseIf login() = True Then
        Welcome.Show()
        Me.Close()
    Else
        MessageBox.Show(loginerror, "Login Message")
    End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    AcceptButton = Button1
    Me.Show()
    Application.DoEvents()
    txtuser.Focus()
End Sub

Private Sub txtpass_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpass.TextChanged

End Sub

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

End Sub

Private Sub txtuser_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtuser.TextChanged

End Sub

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

End Sub

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

End Sub

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

End Sub

结束类


I am using VB.NET and microsoft access as my database, i am new to VB.NET and i tried to make different access levels depending on the current role.For example, After logging in, Admin will proceed to the main page And if users logs in, they will be directed to a different page. I have already set the different roles in my database, and i found some coding online to help me

However i keep getting the error 'UserRole' is not declared. It may be inaccessible due to its protection level. Do i need to declare UserRole first? if so, how do i do it? Any help would be much appreciated , thank you :)

Public Class Form1 Dim loginerror As String Dim UserRole As String Public Function login() Dim DBconn As New ADODB.Connection Dim user As New ADODB.Recordset

    Dim Username As String
    Dim userDB As String
    Dim passDB As String

    Dim UserFound As Boolean

    DBconn.Open("Provider = Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source = '" & Application.StartupPath & "\LoginDB.mdb'")

    user.Open("UserTable", DBconn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

    UserFound = False
    login = False
    Username = "Username = '" & txtuser.Text & "'" '

    Do
        user.Find(Username)
        If user.BOF = False And user.EOF = False Then
            userDB = user.Fields("Username").Value.ToString

            passDB = user.Fields("Password").Value.ToString

            If userDB <> txtuser.Text Then
                user.MoveNext()
            Else
                UserFound = True
                If passDB = txtpass.Text Then
                    UserRole = user.Fields("roles").Value.ToString
                    user.Close()
                    DBconn.Close()
                    Return True
                Else
                    loginerror = "Invalid Password"
                    user.Close()
                    DBconn.Close()
                    Return False
                End If
            End If
        Else
            loginerror = "Invalid Username"
            user.Close()
            DBconn.Close()
            Return False
        End If
    Loop Until UserFound = True
    user.Close()
    DBconn.Close()
    Return False


End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If login() = True And UserRole = "admin" Then
        adminwelcome.Show()
        Me.Close()
    ElseIf login() = True Then
        Welcome.Show()
        Me.Close()
    Else
        MessageBox.Show(loginerror, "Login Message")
    End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    AcceptButton = Button1
    Me.Show()
    Application.DoEvents()
    txtuser.Focus()
End Sub

Private Sub txtpass_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpass.TextChanged

End Sub

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

End Sub

Private Sub txtuser_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtuser.TextChanged

End Sub

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

End Sub

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

End Sub

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

End Sub

End Class


原文:https://stackoverflow.com/questions/17666765
更新时间:2023-04-16 06:04

最满意答案

此代码导致未定义的行为:

uint32_t *p = (uint32_t *)vector;
uint32_t tmp = p[0];

vector指向的内存是uint64_t类型的对象,但是您可以通过uint32_t类型的左值读取它。 这违反了严格的别名规则。

由于你的程序总是调用这个函数,你的整个程序的行为是不确定的。 因此,当优化器删除导致UB的路径时,您可以期望看到奇怪的优化工件。


另一个问题是您使用%lx打印出uint64_t 。 除非您的系统使用64位长,否则这将不起作用。 要获得正确的说明符,请使用printf("%" PRIx64 "\n", vector); 。 你可能需要#include <inttypes.h>


修复printf格式说明符后,我的系统在-O2和更低的位置提供以下内容,或者使用-fno-strict-aliasing开关:

10000000000000a
touch...
20000000000000a

并在-O3垃圾。


This code causes undefined behaviour:

uint32_t *p = (uint32_t *)vector;
uint32_t tmp = p[0];

The memory pointed to by vector is an object of type uint64_t , however you read it via an lvalue of type uint32_t. This violates the strict aliasing rule.

Since your program always calls this function, the behaviour of your whole program is undefined. So you can expect to see strange optimization artifacts when the optimizer cuts out paths which lead to UB.


Another problem is that you are using %lx to print out a uint64_t. This won't work unless your system uses 64-bit longs. To get the right specifier, use printf("%" PRIx64 "\n", vector); . You may need #include <inttypes.h> for this.


After fixing the printf format specifier, my system gives the following at -O2 and lower, or if using the -fno-strict-aliasing switch:

10000000000000a
touch...
20000000000000a

and garbage at -O3.

相关问答

更多
  • 唯一可以肯定的方法是使用-O2和-O3编译您的应用程序。 此外还有一些-O3包含的单独优化选项,您可以单独打开和关闭。 关于更大的二进制文件的警告,请注意,仅仅比较使用-O2和-O3编译的可执行文件大小在这里并不会有太大的好处,因为它是这里最重要的小型关键内部循环的大小。 你真的需要基准。 这将导致更大的可执行文件,但不应该有任何可衡量的放缓。 The only way to know for sure is to benchmark your application compiled with -O2 a ...
  • 此代码导致未定义的行为: uint32_t *p = (uint32_t *)vector; uint32_t tmp = p[0]; vector指向的内存是uint64_t类型的对象,但是您可以通过uint32_t类型的左值读取它。 这违反了严格的别名规则。 由于你的程序总是调用这个函数,你的整个程序的行为是不确定的。 因此,当优化器删除导致UB的路径时,您可以期望看到奇怪的优化工件。 另一个问题是您使用%lx打印出uint64_t 。 除非您的系统使用64位长,否则这将不起作用。 要获得正确的说明符 ...
  • 让我们使用另一个问题的示例代码 。 编译,但告诉gcc不要组装: gcc -std=c99 -S -O2 test.c 现在我们来看看结果test.s文件中的_atoi函数(Mac OS 10.5上的gcc 4.0.1): .text .align 4,0x90 _atoi: pushl %ebp testl %eax, %eax movl %esp, %ebp movl %eax, %ec ...
  • 要迂腐,有8种不同的有效-O选项,你可以给gcc,虽然有一些意思是一样的事情。 这个答案的原始版本有7个选项。 GCC从此增加了-Og ,总共达到8个 从手册页: -O (与-O1相同) -O0 (不要优化,如果没有指定优化级别,则为默认值) -O1 (最佳化) -O2 (优化更多) -O3 (优化甚至更多) -Ofast (非常积极地优化到突破标准合规性的程度) -Og (优化调试经验)-Og可以实现不干扰调试的优化,它应该是标准编辑 - 调试循环的优化级别,提供合理的优化级别,同时保持快速的编译和良好的 ...
  • (可能)你有一个func堆栈粉碎的可能性,它会覆盖调用者堆栈上的ptr 。 确保func任何数组或结构访问都保留在边界内。 如果不是因为我对gcc 3.x的错误记忆,我会说这几乎肯定是实际发生的事情。 即便如此,这也是最可能的解释。 在这一点上给你带来疑问的好处, 如果你的代码真的在你的问题中发布,那么是的,这可能是一个编译器错误: printf("BEFORE: %p\n", ptr); // ok if (func(ptr, x, y)) { continue; ...
  • 导致分段错误的ICE(内部编译器错误)始终是编译器中的一个错误,因此它会要求您报告该错误。 您应该无法使用任何有效或无效的源代码崩溃编译器。 (有各种各样的事情可能发生,通常涉及拒绝编译无效代码,但崩溃不是其中之一。) 由于GCC 4.6.1是最新版本,为什么不考虑升级到更新版本的GCC(不是4.4.3版本就是旧版本)。 在提交错误报告之前,您应该尽量减少您的复制。 494行之后的所有内容可能都不重要; 幸运的是,您可以将第1行和第493行之间的材料从近500个减少到20个左右。 您当然应该尽可能减少它,同 ...
  • 这取决于编译器的实现。 如果您从未将其地址和符号导出(对于C来说它是默认的,因此您必须使用static ),那么优化器应该启动并优化它。 对于简单的类型( int , float ),您可以合理地期望它可以在整个板上工作,但对于struct更好地检查一下编译器的功能。 对于像我的GCC那样的简单结构,优化它,消除结构并直接传递它的值,将常量加载到CPU寄存器。 对于较大的结构,它可能决定它是不值得的。 您可以生成要检查的代码的汇编列表: avr-gcc -O -S somefile.c 要么 gc ...
  • 是否存在为接受指针参数的纯函数显式定义GCC行为的地方? 行为与不带指针参数的纯函数没有什么不同; 他们可以读取程序中的任何内存,但不能写入内存或执行IO。 通过将pure和const函数编写为inline,你已经非常困惑了。 如果函数体在调用站点可供编译器使用,它可以自己解决被调用函数执行的操作。 pure和const属性在函数体不可见的情况下最有用,因为它将在单独的编译单元中定义。 例如,考虑以下非纯,纯和const函数的集合: __attribute__((__pure__)) int a(); __ ...
  • 您确实在调用fgets(line, 80, fp) ,但目标数组line被定义为40 char的数组。 Amazon EC2上的编译器比您的配置更好或更智能。 如果文件包含超过39个字节的行,则这是一个真正的错误。 顺便提一下,在Mac上作为gcc调用的编译器通常是clang一个实例。 试试gcc --version 。 请注意,您的程序不会检查是否读取了太多数据,也不检查sscanf()转换是否成功。 两者都导致未定义的行为。 这是一个更安全的版本: int loadPriceData(const cha ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)