• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

MySQL Connector .NET, AJAX with username checking

Hi,

I'm trying to use an AJAX function to see if a username already exists in a MySQL database, the function works in VS2005 if I use the debug utility to change the value of 'count' to 1, here is the code:

Private Function UserNameExists(ByVal userName As String) As Boolean
        Dim con As New MySqlConnection(ConnectionStrings("testConn").ConnectionString)
        Dim cmd As New MySqlCommand("Select Count(*) From dk_users Where username = @username", con)
        cmd.Parameters.AddWithValue("@username", userName)

        Dim result As Boolean = False
        Using con
            con.Open()
            Dim count As Integer = CType(cmd.ExecuteScalar(), Integer)

            If count > 0 Then
                result = True
            End If
            con.Close()
        End Using
        Return result
    End Function

But as it stands count is always 0, I've run the SQL through MySQL Query Browser and appended a username to it's parameters manually and count is returning 1, so I don't know why the count is not correct in the function.

Please let me know if you need any more of the code?
0
G0ggy
Asked:
G0ggy
1 Solution
 
Aleksandar BradarićSoftware DeveloperCommented:
>        Dim cmd As New MySqlCommand("Select Count(*) From dk_users Where username = @username", con)

Have you tried not using the parameter, but constructing the SQL by concatenation:
---
        Dim cmd As New MySqlCommand("Select Count(*) From dk_users Where username = '" + userName +"' ", con)
---


 
0
 
G0ggyAuthor Commented:
Talk about going backwards! That worked, thanks.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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