VB.net check username is available


I'm trying to check my mysql database to see if users are in the database in real time.

Green if username is not user - red if not.

code is

 <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <asp:TextBox ID="txtUName" runat="server" 
       <asp:Image ID="imgUsr" runat="server" Visible="false"/>
        <asp:Label ID="lblUsr" runat="server"/>

Open in new window

Imports System.Data
Imports MySql.Data.MySqlClient

Partial Class signup
    Inherits System.Web.UI.Page
	Dim MysqlConn As MySqlConnection
Dim con As New mySqlConnection(ConfigurationManager.ConnectionStrings("dbconnection").ConnectionString)
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub

Protected Sub txtUName_TextChanged(sender As Object, e As EventArgs)
 If txtUName.Text <> String.Empty Then
  Dim strSelect As String = "SELECT COUNT(*) FROM members WHERE Username = txtUName.Text.Trim().ToString()"
  Dim cmd As New mySqlCommand(strSelect, con)

  Dim result As Integer = DirectCast(cmd.ExecuteScalar(), Int32)

  If result >= 1 Then
   imgUsr.ImageUrl = "unavailable.png"
   imgUsr.Visible = True
   lblUsr.Text = "Username not available"
   lblUsr.ForeColor = System.Drawing.Color.Red
   imgUsr.ImageUrl = "tick.png"
   imgUsr.Visible = True
   lblUsr.Text = "Available"
   lblUsr.ForeColor = System.Drawing.Color.Green
  End If
 End If

End Sub

End Class

Open in new window

but it does nothing live??? no red or green

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
Don't know if this is the issue, but this line does not look correct:
Dim strSelect As String = "SELECT COUNT(*) FROM members WHERE Username = txtUName.Text.Trim().ToString()"

Open in new window

It should look something like:
Dim strSelect As String = "SELECT COUNT(*) FROM members WHERE Username = '" + txtUName.Text.Trim().ToString() + "'"

Open in new window

runnerjp2005Author Commented:
Thanks Shaun - you are correct and i updated the code to reflect this but it still does not work sadly
Shaun KlineLead Software EngineerCommented:
Do you need to include the <triggers> tag as part of your UpdatePanel, as mentioned here?
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

runnerjp2005Author Commented:
I tried to stick it round the textbox as that would be the trigger with no luck sadly
Shaun KlineLead Software EngineerCommented:
Have you attempted to debug the code to see if the event is firing?
I would suggest that you use parameters instead of text concatenation as you are open to SQL injection attacks as it stands.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.