VB 错误:“mAuto1”没有声明。由于其保护级别,它可能无法访问”。需要解决方案

发布于 2024-11-09 05:36:27 字数 1894 浏览 0 评论 0原文

我是 C# 和 Visual Basic 编程新手。我正在使用 Visual Studio 2010,我正在尝试从 mysql 数据库检索一些数据。使用 wamp 安装。

我已经通过转到“项目”、“应用程序属性”、“设置”来设置与数据库的连接。

我有这个错误“'mAuto1'未声明。由于其保护级别,它可能无法访问”,我似乎无法解决它。

下面的代码用于简单的检索:

Public Class Form1

    Private procAuto As CALCOM.Auto

    Private Function Connect_To_Database() As Boolean
        Dim mErrorNumQuery As Long
        Dim mReturn As Boolean
        procAuto = New CALCOM.Auto
        procAuto.Connect(mErrorNumQuery)
        If mErrorNumQuery = 0 Then
            mReturn = True
        Else
            mReturn = False
        End If
        Connect_To_Database = mReturn
    End Function

    Private Function Get_Weight_By_TicketNumber(ByVal mTicketNumber As String, ByRef mAuto1 As Long, ByRef mAuto2 As Long, ByRef mTotalWeight As Long) As Boolean
        Dim mErrorNumQuery As Long
        Dim mXtr As New CALCOM.xTr
        Dim mRec As ADODB.Recordset
        Dim mReturn As Boolean
        mRec = mXtr.GetList("Select Auto1,Auto2,TotalWeight From txticket Where TicketCode = '" & mTicketNumber & "'", , , mErrorNumQuery)
        If mErrorNumQuery = 0 Then
            mReturn = True
            If mRec.RecordCount <> 0 Then
                mRec.MoveFirst()
                mRec.MoveFirst()
                mAuto1 = mRec.Fields("Auto1").Value
                mAuto2 = mRec.Fields("Auto2").Value
                mTotalWeight = mRec.Fields("TotalWeight").Value
            End If
        Else
            mReturn = False
        End If
        Get_Weight_By_TicketNumber = mReturn
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = mAuto1 <--------------------problem here
    End Sub
End Class

这个程序只是一个测试,看看我是否可以在表单标签上显示 mysql 查询的结果。我想通过单击按钮来显示结果

如何修复该错误?任何帮助表示赞赏。

I am new to programming in c# and visual basic. I am using visual studio 2010 and I am trying to retrieve some data from a mysql database. Installed using wamp.

I have already set connection to the database by going to 'Project', 'Application Properties', 'Settings'.

I have this error "'mAuto1' is not declared. It may be inaccessible due to its protection level" and I cant seem to solve it.

The code below is for a simple retrieve:

Public Class Form1

    Private procAuto As CALCOM.Auto

    Private Function Connect_To_Database() As Boolean
        Dim mErrorNumQuery As Long
        Dim mReturn As Boolean
        procAuto = New CALCOM.Auto
        procAuto.Connect(mErrorNumQuery)
        If mErrorNumQuery = 0 Then
            mReturn = True
        Else
            mReturn = False
        End If
        Connect_To_Database = mReturn
    End Function

    Private Function Get_Weight_By_TicketNumber(ByVal mTicketNumber As String, ByRef mAuto1 As Long, ByRef mAuto2 As Long, ByRef mTotalWeight As Long) As Boolean
        Dim mErrorNumQuery As Long
        Dim mXtr As New CALCOM.xTr
        Dim mRec As ADODB.Recordset
        Dim mReturn As Boolean
        mRec = mXtr.GetList("Select Auto1,Auto2,TotalWeight From txticket Where TicketCode = '" & mTicketNumber & "'", , , mErrorNumQuery)
        If mErrorNumQuery = 0 Then
            mReturn = True
            If mRec.RecordCount <> 0 Then
                mRec.MoveFirst()
                mRec.MoveFirst()
                mAuto1 = mRec.Fields("Auto1").Value
                mAuto2 = mRec.Fields("Auto2").Value
                mTotalWeight = mRec.Fields("TotalWeight").Value
            End If
        Else
            mReturn = False
        End If
        Get_Weight_By_TicketNumber = mReturn
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = mAuto1 <--------------------problem here
    End Sub
End Class

This program was just a test to see if I can display results of a mysql query on a form label. I wanted to display results on the click of a button

How do I fix the error? Any help appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅暮の光 2024-11-16 05:36:27

mAuto1 变体是 Get_Weight_By_TicketNumber 函数中的本地变体,您不能在函数外部使用它。如果需要,可以声明一个类级别变量并将其设置为 mAuto1 的值。

The mAuto1 variant is a local one at Get_Weight_By_TicketNumber function, you can't use it outside the function. If you want, declare a class-level variant and set it to the value of mAuto1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文