• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • 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
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.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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