Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Validation of Textbox

Validation of Textbox

Scheduled Pinned Locked Moved Visual Basic
databasecsharpdata-structuresregex
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Larry White
    wrote on last edited by
    #1

    I am using VB.NET (2003) to create a Windows form to interface with a SQL 2000 database. I need to validate the user input of an employee number with the table that contains the valid numbers. All I want to do is validate the information and move on, or pop a messagebox up. My problem is getting the code right to loop the array for the comparison function. I also hope to match the USERID and integrate this into the validation process to further verify that the proper person is being identified. Thank you in advance. :o LW:-D LWhite

    A 1 Reply Last reply
    0
    • L Larry White

      I am using VB.NET (2003) to create a Windows form to interface with a SQL 2000 database. I need to validate the user input of an employee number with the table that contains the valid numbers. All I want to do is validate the information and move on, or pop a messagebox up. My problem is getting the code right to loop the array for the comparison function. I also hope to match the USERID and integrate this into the validation process to further verify that the proper person is being identified. Thank you in advance. :o LW:-D LWhite

      A Offline
      A Offline
      Agus Budianto
      wrote on last edited by
      #2

      i don't know if this will help you but i hope it will my suggestion is: 1. you save the use input in a variable 2. query database for that input 3. if the query result is 0 then the employee number is not exist, give warning 4. else then number is exist go to next process I'm assuming you have a table called TabEmployees with a field called EmployeeNo and using microsoft access 2000 database file. here's the code

      private function isEmpExist(byval EmpNo as integer) as boolean
      dim CN as new oledbconnection
      dim R as integer
      cn.connectionstring="provider=microsoft.jet.oledb.4.0"
      dim Cmd as oledbcommand=cn.createcommand
      with cmd
      'set commandtype as commandtext
      .commandtext="SELECT EmployeeNo FROM TabEmployees WHERE EmployeeNo = " & EmpNo.tostring.trim
      end with
      r=cmd.executenonquery
      if isnothing(r) then
      return false
      else
      return true
      end if
      cn.close
      end function

      hope you find this useful, and i'm sorry if this code doesn't do as it should, but i think it will only might produce syntax error, coz i'm typing it directly here without VB. well then good luck!

      A L 2 Replies Last reply
      0
      • A Agus Budianto

        i don't know if this will help you but i hope it will my suggestion is: 1. you save the use input in a variable 2. query database for that input 3. if the query result is 0 then the employee number is not exist, give warning 4. else then number is exist go to next process I'm assuming you have a table called TabEmployees with a field called EmployeeNo and using microsoft access 2000 database file. here's the code

        private function isEmpExist(byval EmpNo as integer) as boolean
        dim CN as new oledbconnection
        dim R as integer
        cn.connectionstring="provider=microsoft.jet.oledb.4.0"
        dim Cmd as oledbcommand=cn.createcommand
        with cmd
        'set commandtype as commandtext
        .commandtext="SELECT EmployeeNo FROM TabEmployees WHERE EmployeeNo = " & EmpNo.tostring.trim
        end with
        r=cmd.executenonquery
        if isnothing(r) then
        return false
        else
        return true
        end if
        cn.close
        end function

        hope you find this useful, and i'm sorry if this code doesn't do as it should, but i think it will only might produce syntax error, coz i'm typing it directly here without VB. well then good luck!

        A Offline
        A Offline
        Agus Budianto
        wrote on last edited by
        #3

        ups sorry, i think i made mistake in that code, the line

        r=cmd.executenonquery

        should have been

        r=cmd.executescalar

        , sorry...:-O

        1 Reply Last reply
        0
        • A Agus Budianto

          i don't know if this will help you but i hope it will my suggestion is: 1. you save the use input in a variable 2. query database for that input 3. if the query result is 0 then the employee number is not exist, give warning 4. else then number is exist go to next process I'm assuming you have a table called TabEmployees with a field called EmployeeNo and using microsoft access 2000 database file. here's the code

          private function isEmpExist(byval EmpNo as integer) as boolean
          dim CN as new oledbconnection
          dim R as integer
          cn.connectionstring="provider=microsoft.jet.oledb.4.0"
          dim Cmd as oledbcommand=cn.createcommand
          with cmd
          'set commandtype as commandtext
          .commandtext="SELECT EmployeeNo FROM TabEmployees WHERE EmployeeNo = " & EmpNo.tostring.trim
          end with
          r=cmd.executenonquery
          if isnothing(r) then
          return false
          else
          return true
          end if
          cn.close
          end function

          hope you find this useful, and i'm sorry if this code doesn't do as it should, but i think it will only might produce syntax error, coz i'm typing it directly here without VB. well then good luck!

          L Offline
          L Offline
          Larry White
          wrote on last edited by
          #4

          Thank you very much for responding. I plugged in the code and modified to match my database settings and have a syntax error. I should be able to find the error with a little troubleshooting. The error appears to be in the .CommandText line. Here is my modified code: Private Function isEmpExist(ByVal EmpNo As Integer) As Boolean Dim CN As New SqlConnection Dim R As Integer CN = (New SqlConnection("Integrated Security=False; User id= testuser; password= xxx; Server=xxx; Initial Catalog=Galley")) Dim Cmd As SqlCommand = CN.CreateCommand With Cmd 'set commandtype as commandtext .CommandText = "SELECT emplid FROM users WHERE emplid = " & editEMPLID.ToString.Trim End With CN.Open() R = Cmd.ExecuteScalar If IsNothing(R) Then Return False Else Return True End If CN.Close() End Function Again, I very much appreciate the assist. I've been banging my head against the wall for a few days on this one. This should be a simple comparison and validation.:~ LWhite

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups