I want to create a textbox which contents are validated every time the text in it changes. And an image is displayed beside the textbox if it is correct and another image shows up if its not correct. Pretty much like ajax.
Heres the method which I called from the class.
Public Sub read1()
cmd.CommandText = "SELECT * FROM testdb WHERE Name='" & name & "'"
Try
rdr = cmd.ExecuteReader
Dim n As String
If rdr.HasRows Then
n = rdr("Name").ToString
Form1.PictureBox1.Image = Image.FromFile("C:\wamp\www\Dropbox\Public\Check-icon.png")
Else
Form1.PictureBox1.Image = Image.FromFile("C:\wamp\www\Dropbox\Public\Delete-icon.png")
End If
Catch ex As Exception
And here the event which calls for the method:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
x.name = TextBox1.Text
x.read1()
End Sub
End Try
End Sub
Problem is, the method seems to be only called once. And the first image that was displayed stays the same even after inputting a data which does not exist in the database.
I’m connecting this program to a mysql database using odbc. Can you help me determine whats the problem and how to fix it?
Heres the screenshot:

With a DataReader object, you have to call the
Readmethod before you can access the row. I think it would need to look like the following. I am guessing at the VB.Net syntax and method name, but I am reasonably sure it would be simply rdr.Read.Edit In addition, you probably need to close the DataReader. Some .NET data providers allow only a single reader to be open at a time on a given connection, and it seems likely that the ODBC provider is one of them. Without a specific call to close it, you would be relying on the garbage collector to clean it up:
And while this has nothing to do with the question directly, you should probably use a parameterized query to avoid an SQL injection attack.