Results 1 to 2 of 2

Thread: Validating textbox in a webform

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    Unhappy Validating textbox in a webform

    I am new to webforms but have created a webform that will add a new user to the database after they fill in all necessary fields. That all works. Now what I want to do is when they fill in their unique ID and they click on the add user button, instead of just adding the user, check to see if that user id already exists in the database and if it does message the user that it does exist. So far I have been using labels as my messages using the visibility property. Not sure if that is the correct way or not but I know msgbox dont work with webforms. I have an sql connectin and the sql command setup but not sure what is next. The field SN is the unique ID.

    VB Code:
    1. Me.cnAdd = New System.Data.SqlClient.SqlConnection
    2.         Me.cmAdd = New System.Data.SqlClient.SqlCommand
    3.         '
    4.         'cnAdd
    5.         '
    6.         Me.cnAdd.ConnectionString = "workstation id=""S-KG-CFSCE-2098"";packet size=4096;integrated security=SSPI;data s" & _
    7.         "ource=""KG-CFSCE-2B"";persist security info=False;initial catalog=CF98"
    8.         '
    9.         'cmAdd
    10.         '
    11.         Me.cmAdd.CommandText = "SELECT SN FROM dbo.ID"
    12.         Me.cmAdd.Connection = Me.cnAdd

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    How about using ExecuteScalar() to see if a column is returned. If it is returned, the ID exists, else if nothing is returned, you know its empty.

    You'll obviously need to change the SQL Query you wrote to something else, like

    Code:
    "SELECT SN FROM dbo.ID WHERE SN = '" & txtUserEntry.Text & "'"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width