Code for searching username field in database

surendarj

New member
Joined
May 27, 2010
Messages
2
Programming Experience
Beginner
surendarj-albums-pics-picture24-untitled.jpg

i have one registration form which consists of username, password, confirmpassword and Register button.
When i will be typing the username, it should show whether the username is available or not. and i have changed the username column as primary key in sql database.

Private Sub txtusername1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtusername1.KeyUp
Dim da As New SqlDataAdapter("select * from Register", con)
da.Fill(ds, "Register1")
If txtusername1.Text = ds.Tables("Register1").Rows(0)(0).ToString Then
lblusernameerror.Text = "Username is not available,choose another"
Else
lblusernameerror.Text = "Username is available"
End If
End Sub

In the Bolded line, it is reading only one username but i need to read all the columns....

here i have written key up event in the text box of username, but here it is loading only one username...


I am using visual basic 2008 and i am writing the program in disconected architecture in vb.net
thanks in advance..
please help me soon
 
Last edited:
Execute a query that gets a count of a particular value, e.g.
VB.NET:
SELECT COUNT(*) FROM Users WHERE UserName = @UserName
Create a SqlCommand and call ExecuteScalar. It will return 0 if the user name is available or 1 if it's in use.
 
Back
Top