I'm getting an error in my VB.NET application that connects to my SQL database. It connects fine, but for some reason I can't fix this error. When I try to fix it, it moves from one part of my script to another part of my script (both of which were working yesterday). The error details are:
Unfortunately, it's difficult for me to describe how I produced this result, because it has happened in multiple parts of my code, and the only thing that these parts have in common is their interaction with Listbox1.
The first part of code to get this error was:
Dim sqlpage As MySqlCommand = New MySqlCommand("SELECT * FROM [" & frmMain.ListBox1.SelectedItem.value & "]", con)
Then I got the same exact error for:
Private Sub ListBox1_SelectedValueChanged( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles ListBox1.SelectedValueChanged
Try
Form1.Label1.Text = ListBox1.SelectedItem
Form1.Show()
Catch myerror As MySqlException
MessageBox.Show("Error Setting Up Project Page: " & myerror.Message)
End Try
End Sub
More specifically:
Form1.Label1.Text = ListBox1.SelectedItem
And then I got it a few more times, but I think the examples above will suffice.
Since there are no "With Block Variables" in the examples above then the only other option is that it's object related. I've tried different methods of defining and redefining the object variables related to the error. However, the results are the same.
In response to Juxtaposition's answer, my original problem has been solved however two new problems have come up specifically because I turned Option Strict on.
- The first is:
Error1: Option Strict On disallows late binding.
The code in question is:
Try
' Retrieving the projects list.
con.Open()
DataAdapter2.SelectCommand = sqlprojects
DataAdapter2.Fill(ds2, "projects")
ListBox1.Items.Clear()
For Each DataRow In ds2.Tables("projects").Rows
' Error occurs on the line below
ListBox1.Items.Add(DataRow("project_name"))
Next
con.Close()
Catch myerror As MySqlException
MessageBox.Show("Error Retrieving Projects List: " & myerror.Message)
End Try
- The second is:
Error 2: Option Strict On disallows implicit conversions from 'Object' to 'String'.
The code in question is:
Private Sub ListBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedValueChanged
Try
If ListBox1.SelectedItem IsNot Nothing Then
' Error occurs on the line below
Form1.Label1.Text = ListBox1.SelectedItem
End If
Form1.Show()
Catch myerror As MySqlException
MessageBox.Show("Error Setting Up Project Page: " & myerror.Message)
End Try
End Sub
It worked out... so I thank all of you for your time and patience.