我试图引用创建的图片框的标签,然后删除访问表中的记录,该记录的ID对应于图片框的标签。但是,当我尝试引用图片框的标签时,我只会得到一个null引用异常错误。您认为您可以帮忙吗?
这是创建图片框的代码!现在我还无法测试,但是使用此代码,插入的第一张图片的标签应为1,第二张图片的标签应为2,第三张图片的标签为3,依此类推...
' Declared in Form1 (global)
Dim cardPictureBox As PictureBox
Public Sub bigpictureloader()
Dim cardcount As Integer
Dim cards As List(Of String) = New List(Of String)
cards.Add(imageurltxt.Text)
'Create a placeholder variable
Dim cardPictureBox As PictureBox
'Loop through every selected card URL
For Each url As String In cards
'Create a new PictureBox
cardPictureBox = New PictureBox()
cardPictureBox.Size = New Size(100, 100)
cardPictureBox.SizeMode = PictureBoxSizeMode.Zoom
cardPictureBox.WaitOnLoad = False
AddHandler cardPictureBox.Click, AddressOf imagehandler
cardcount = 0
counter += 1
cardcount = counter
cardPictureBox.Tag = Convert.ToInt32(cardcount)
'Add the PictureBox to the Form
Me.Controls.Add(cardPictureBox)
If imageurltxt.Text = "" Then
cardPictureBox = Nothing
Else
cardPictureBox.LoadAsync(url)
TableLayoutPanel1.Controls.Add(cardPictureBox, 0, 0)
End If
'Load the image asynchronously
' cardPictureBox.LoadAsync(url)
'TableLayoutPanel1.Controls.Add(cardPictureBox, 0, 0)
Next
End Sub
这是删除数组记录的代码(这是图像处理程序)
Private Sub testdelete()
'THIS SAVES TO THE DEBUG ACCESS DATABASE!!!!!
Using conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source = FULL YUGIOH ACCESS DATABASE.accdb;")
Using command As New OleDbCommand("Delete From cmon11 Where ID= @ID;", conn)
command.Parameters.Add("@ID", OleDbType.Integer).Value = CInt(cardpicturebox.tag)
conn.Open()
command.ExecuteNonQuery()
End Using
End Using
End Sub