As the title says, I'm getting an error from my code below, which basically selects multiple inputs on a ListView
, and puts it inside a database. Here's the code:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For Each item As ListViewItem In ListView1.SelectedItems
Dim StudentID = Integer.Parse(item.SubItems(0).Text)
Dim FirstName = item.SubItems(1).Text
Dim LastName = item.SubItems(2).Text
DBConn()
SQLSTR = "INSERT INTO '" & TextBox4.Text & "' (StudentID, FirstName, LastName) VALUES ('" & StudentID & "', '" & FirstName & "', '" & LastName & "') "
alterDB()
MsgBox("Students succesfully added", msgboxtitle)
Next
MsgBox("Students added!", , msgboxtitle)
End Sub
The exact error is:
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Additional information: Conversion from string "" to type 'Integer' is not valid.