Hey guys, I've looked around the forum and seen a few answers that looked like it should have solved the problem - but didn't. I'm trying to create a function that will check the database and compare it with the value of my label. (Basically a Version Checker) If it is the same, then nothing is displayed, if not, then I'll disable some buttons and change another text to display something. Here's the code I have so far...

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Panel2.Visible = False
        Panel1.Visible = False
        Panel4.Visible = False
        MySQLConnection = New MySqlConnection
        MySQLConnection.ConnectionString = "server=db4free.net;Port=3306; User ID=*****; password=*****; database=*****;"              'The problem isn't this ;)
        MySQLConnection.Open()

        Dim MyAdapter As New MySqlDataAdapter
        Dim SqlQuary = "SELECT VersionNumber From Table32;"
        Dim Command As New MySqlCommand
        Command.Connection = MySQLConnection
        Command.CommandText = SqlQuary
        MyAdapter.SelectCommand = Command
        Dim Mydata As MySqlDataReader
        Mydata = Command.ExecuteReader
            If Mydata.HasRows = 0 Then
                MsgBox("Could not connect with database. Check firewall and/or try again at a later time.")
            Else
            If Mydata(0).Read = Label2.Text Then
                Button5.Enabled = False
                LinkLabel1.Text = "YOU NEED TO UPDATE!"
            Else
                LinkLabel1.Text = ""
            End If
        End If
        Mydata.Close()

    End Sub

I'm positive that I'm just not putting the correct calling reference in this part:

If Mydata(0).Read = Label2.Text Then

If anyone could shed some light on the subject, I'd appreciate it! Thanks!

Edited 5 Years Ago by maggoteer: n/a

You cannot have like:

If Mydata(0).Read = Label2.Text Then

This does nothing. Read is a method, and not a property.
SqlDataReader class cannot be compared with some string.
What you can do, is to compare an actual reader with it, like:

If Mydata(0).Read() = Label2.Text Then
	Button5.Enabled = False
	LinkLabel1.Text = "YOU NEED TO UPDATE!"
End If

you can alseo try it in a long way:

If Mydata.HasRows = 0 Then
	Interaction.MsgBox("Could not connect with database. Check firewall and/or try again at a later time.")
Else
	If Mydata().Read() Then
		If DirectCast(MyData(0), String) = Label2.Text Then
			Button5.Enabled = False
			LinkLabel1.Text = "YOU NEED TO UPDATE!"
			Exit
		Else
			LinkLabel1.Text = ""
		End If
	Else
		LinkLabel1.Text = ""
	End If
End If

Blargle! Both code snippets you offered did not seem to do the trick. The code does not show any errors, but when I debug the program the "LinkLabel1.text" does not change in any way. It doesn't go away OR present "YOU NEED TO UPDATE!"

Even if it there wasn't anything to read from within the database (trust me, there is) it should still either change LinkLabel1.Text to "" or give the "Could not connect with database" error, right?

Good news! I finally fixed my problem using a "while" statement. For all those maybe in the same pickle as me try using this bit of code:

If Mydata.HasRows = 0 Then
            MsgBox("Could not connect with database. Check firewall and/or try again at a later time.")
        Else
            While Mydata.Read()
                If Mydata(0).ToString = Label2.Text Then
                    LinkLabel1.Text = ""
                Else
                    LinkLabel1.Text = "Update to Version:" & Mydata(0).ToString
                End If
            End While
        End If
        Mydata.Close()

@Mitja Bonca - I appreciate the fast response and help, I appreciate it!

Hmm,
try this code, this has got to work:
- if only there are data in database (you say there are)
- if the text in Label2 is same as data read from database

If Mydata.Read() Then
	If DirectCast(Mydata(0), String) = Label2.Text Then
		Button5.Enabled = False
		LinkLabel1.Text = "YOU NEED TO UPDATE!"
			'reader reads, but the string is not the same as in the label2!!
	Else
	End If
Else
	LinkLabel1.Text = ""
End If
Mydata.Close()

Edited 5 Years Ago by Mitja Bonca: n/a

TO ADD:
Now when I read your last post, and if you use while loop this means you have more rows in dataBase. This is now different.
Try using my code, but use WHILE loop instead.

This question has already been answered. Start a new discussion instead.