I have this new vb.net project (MedicalCost) having this error "The type initializer for 'MedicalCost.Constants' threw an exception." when running the sub.. I've already done this before on my previous project and everything works fine when I'm declaring ang public varible on my module but now in my current project its not working.
here is my code on my module(Constants):
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Data.Odbc
Imports System.Windows.Forms
Public Module Constants
Public ppiconn As New SqlConnection("Dsn=pandiman2002connectdsn;server=ppi;uid=sa;database=Pandimandata2002")
'Dsn=pandiman2002connectdsn;description=PPI Database;uid=sa;app=Microsoft® Visual Studio® 2010;wsid=CRWUSER17-PC;database=Pandimandata2002
Public da As New SqlDataAdapter
Public comm As New SqlCommand
Public dr As SqlDataReader
Public ds As New DataSet
Public x As String
End Module
when im running the sub on my frm_add
here is my code
Sub search_crew()
Try
x = "(isnull(ltrim(rtrim(firstname)),'') + ' ' + isnull(ltrim(rtrim(mi)),'') + ' ' + " _
& "isnull(ltrim(rtrim(lastname)),'') like '%" & Replace(searchbox.Text, " ", "%") & "%' " _
& " or isnull(ltrim(rtrim(lastname)),'') + ' ' + isnull(ltrim(rtrim(mi)),'') + ' ' + " _
& "isnull(ltrim(rtrim(firstname)),'') like '%" & Replace(searchbox.Text, " ", "%") & "%' " _
& "or legal_records.caseno like '%" & UCase(searchbox.Text) & "%')"
ppiconn.Close()
ppiconn.Open()
Pandimandata2002DataSet.EnforceConstraints = False
da = New SqlDataAdapter(select_tblcrw & "where " & x, ppiconn)
da.Fill(Pandimandata2002DataSet.tblCrew)
da.Dispose()
ppiconn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
I noticed that any variable declared from module is the reason why this error "The type initializer for 'MedicalCost.Constants' threw an exception." occurs.
can anyone help me. I already spent 1 hour searching for this error and nothings helps me. tnx!