VB.net check username is available

Hello,

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">
   <ContentTemplate>
       UserName: 
        <asp:TextBox ID="txtUName" runat="server" 
                   ontextchanged="txtUName_TextChanged" 
                   AutoPostBack="True"/>
        
       <asp:Image ID="imgUsr" runat="server" Visible="false"/>
        <asp:Label ID="lblUsr" runat="server"/>
        
        
    </ContentTemplate>
    </asp:UpdatePanel>

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)

  
  cmd.Parameters.Add(txtUName.Text.Trim().ToString())
  con.Open()
  Dim result As Integer = DirectCast(cmd.ExecuteScalar(), Int32)
  con.Close()

  If result >= 1 Then
   imgUsr.ImageUrl = "unavailable.png"
   imgUsr.Visible = True
   lblUsr.Text = "Username not available"
   lblUsr.ForeColor = System.Drawing.Color.Red
  Else
   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

http://runningprofiles.com/signup.aspx
runnerjp2005Asked:
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

0
runnerjp2005Author Commented:
Thanks Shaun - you are correct and i updated the code to reflect this but it still does not work sadly
0
Shaun KlineLead Software EngineerCommented:
Do you need to include the <triggers> tag as part of your UpdatePanel, as mentioned here?
http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers
0
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
0
Shaun KlineLead Software EngineerCommented:
Have you attempted to debug the code to see if the event is firing?
0
CodeCruiserCommented:
I would suggest that you use parameters instead of text concatenation as you are open to SQL injection attacks as it stands.
0

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
ASP.NET

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.