[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

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
0
runnerjp2005
Asked:
runnerjp2005
  • 3
  • 2
1 Solution
 
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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now