类型初始化器< module>错误 [英] The type initializer <module> error

查看:57
本文介绍了类型初始化器< module>错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行搜索并在datagridview上进行检索,但是在单击仪表板(菜单)中的employeesView按钮后,出现了错误类型初始化器引发异常。。如何解决?谢谢大家!

I'm making a search and retrieve it on datagridview, but I got this error "The type initializer for threw an exception.", after I clicked the button employeesView in the dashboard (menu). How to fix it? Thanks guys!!

错误:

Error:

    Private Sub btnEmployees_Click(sender As Object, e As EventArgs) Handles btnEmployees.Click
        employeesView.TopLevel = False
        Me.panelMain.Controls.Add(employeesView)
        Me.panelHeader.BackColor = Color.FromArgb(0, 160, 220)
        employeesView.BringToFront()
        employeesView.Show()
    End Sub

publicVariables.vb

Imports System.Data.SqlClient

Module publicVariables

    Public connection As SqlConnection
    Public command As SqlCommand
    Public dataReader As SqlDataReader
    Public dataAdapter As SqlDataAdapter

    Public dataTable As DataTable

    Public search_query As String
    Public insert_query As String
    Public delete_query As String
    Public update_query As String

    Public result As Integer

    Public getNumber As String = "0"

    Public productsView As New Products
    Public dashboardView As New Dashboard
    Public employeesView As New Employee
    Public salesView As New Sales
    Public logsView As New LogManager

End Module

搜索代码:

Public Sub retrieveEmployeesforSearch()
        Try
            dbConnection()
            search_query = "SELECT * FROM tblemployee_information as emp_info INNER JOIN tblemployee_account as emp_account ON emp_account.employee_number = emp_info.employee_number WHERE emp_info.employee_first_name LIKE @employee_first_name ORDER BY emp_info.employee_first_name;"
            command = New SqlCommand
            With command
                .Connection = connection
                .CommandText = search_query
                .Parameters.Clear()
                .Parameters.AddWithValue("@employee_first_name", employeesView.txtSearchEmployee.Text)
                .ExecuteNonQuery()
            End With
            dataTable = New DataTable
            dataAdapter = New SqlDataAdapter
            dataAdapter.SelectCommand = command
            dataAdapter.Fill(dataTable)
            employeesView.EmployeeDGV.DataSource = dataTable
        Catch ex As SqlException
            MsgBox("Error : " + ex.Message)
        Finally
            connection.Close()
            command.Dispose()
        End Try
    End Sub

如果textbox.text文本已更改,则检索搜索数据

Retrieve search data if textbox.text textchanged

Private Sub txtSearchEmployee_TextChanged(sender As Object, e As EventArgs) Handles txtSearchEmployee.TextChanged
        retrieveEmployeesforSearch()
    End Sub


推荐答案

我不知道您的意思,但是我认为此代码也存在一些错误:

I don't know what you mean but I think there is also some wrong with this code:

search_query = "SELECT * FROM tblemployee_information as emp_info INNER JOIN tblemployee_account as emp_account ON emp_account.employee_number = emp_info.employee_number WHERE emp_info.employee_first_name LIKE @employee_first_name ORDER BY emp_info.employee_first_name;"

您可以从此链接。希望会对您有所帮助。

you may refer from this link. hopefully, it will help you.

这篇关于类型初始化器< module>错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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