我有一行代码在加载用户控件时从另一个表单中提取值
usernameconstant.Text = Mainpage.usernameconstantmain.Text
这在正常情况下工作正常,但我需要在同一页面上使用PDF阅读器,当我添加Adobe PDF阅读器时,应用程序完全停止工作,并在上面的代码中给出了这个错误。
System.InvalidOperationException: 'The form referred to itself during construction from a default instance, which led to infinite recursion. Within the Form's constructor refer to the form using 'Me.''
我尝试删除从另一个页面中提取值的第一行代码,看看它是否真的导致了问题并且错误没有再弹出,但我仍然需要使用PDF阅读器的单独表单中的值并且我不确定为什么这个错误会不断出现。
Public Class Submissioncontrol
Dim conn As New MySqlConnection
Dim Myconnection As String = "server=localhost;user id=root;password=password;database=project"
Dim cmd As New MySqlCommand
Dim da As New MySqlDataAdapter
Dim result As Integer
Dim imgpath As String
Dim arrImage() As Byte
Dim sql As String
Dim connection As MySqlConnection
Dim ride As MySqlCommand
Public Property studentid
Public Property title
Public Property deadline
Private Sub Submissioncontrol_Load(sender As Object, e As EventArgs) Handles MyBase.Load
usernameconstant.Text = Mainpage.usernameconstantmain.Text
todaysdate.Text = Today
Dim number As New Random
idbox.Text = number.Next(1, 1000000)
End Sub
Private Sub Submit_Click(sender As Object, e As EventArgs)
connection = New MySqlConnection
connection.ConnectionString =
"server=localhost;userid=root;password=aaronwong;database=finalyearproject"
' Establishes connection to mysqldatabase '
Dim reader As MySqlDataReader
Try
connection.Open()
Dim aaasaccess As String
aaasaccess = "insert into finalyearproject.studentsubmissions (submissionid, studentnumber, time, date, deadline, title, work, modulename) values ('" & idbox.Text & "','" & usernameconstant.Text & "','" & todaystime.Text & "','" & todaysdate.Text & "','" & deadlinesubmission.Text & "','" & titlesubmission.Text & "','" & workload.Text & "','" & modulename.Text & "')"
' inserts into specific database schema with the named columns '
ride = New MySqlCommand(aaasaccess, connection)
reader = ride.ExecuteReader
MessageBox.Show("Created")
connection.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
connection.Dispose()
End Try
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
todaystime.Text = TimeOfDay
End Sub
Private Sub Button2_Click_2(sender As Object, e As EventArgs) Handles Button2.Click
Try
conn.ConnectionString = Myconnection
conn.Open()
sql = "insert into studentsubmissions(submissionid, studentnumber, time, date, deadline, title, work, modulename) VALUES (@subid, @stunumber, @subtime, @subdate, @workdeadline, @stutitle, @stuwork, @workmodulename)"
cmd.Connection = conn
cmd.CommandText = sql
cmd.Parameters.AddWithValue("@subid", idbox.Text)
cmd.Parameters.AddWithValue("@stunumber", usernameconstant.Text)
cmd.Parameters.AddWithValue("@subtime", todaystime.Text)
cmd.Parameters.AddWithValue("@subdate", todaysdate.Text)
cmd.Parameters.AddWithValue("@workdeadline", deadlinesubmission.Text)
cmd.Parameters.AddWithValue("@stutitle", titlesubmission.Text)
cmd.Parameters.AddWithValue("@stuwork", workload.Text)
cmd.Parameters.AddWithValue("@workmodulename", modulename.Text)
cmd.ExecuteNonQuery()
MessageBox.Show("Created")
cmd.Parameters.Clear()
conn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
> Final Year Project.exe!Final_Year_Project.Submissioncontrol.Submissioncontrol_Load(Object sender, System.EventArgs e) Line 30 Basic Symbols loaded.
[External Code] Annotated Frame
Final Year Project.exe!Final_Year_Project.Submissioncontrol.New() Line 13 Basic Symbols loaded.
[External Code] Annotated Frame
Final Year Project.exe!Final_Year_Project.Submissioncontrol.Submissioncontrol_Load(Object sender, System.EventArgs e) Line 30 Basic Symbols loaded.
[External Code] Annotated Frame
Final Year Project.exe!Final_Year_Project.Submissioncontrol.New() Line 13 Basic Symbols loaded.
[External Code] Annotated Frame
Final Year Project.exe!Final_Year_Project.Login.Button1_Click(Object sender, System.EventArgs e) Line 33 Basic Symbols loaded.
[External Code] Annotated Frame