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. Validate data in a table

Validate data in a table

Scheduled Pinned Locked Moved Visual Basic
helpdatabasesysadminsecuritytesting
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.
  • P Offline
    P Offline
    phokojoe
    wrote on last edited by
    #1

    I have entered data into a database table, "PersonData". It has 5 columns PersonNo Sex Age Married Education. Now I want to write a validation program in vb whereby it opens the "PersonData" and then checks that if person is married, then the spouse has to be of different sex. and if the pesron is married then the age has to be more than 15. There are many incosistencies that I would like my code to check, but if I can be helped with this ones I can handle the others. This I want to run for say about a thousands records. Then I write the validation messages to a text file. This is a sample of the code I have written: Option Explicit Public objConn As ADODB.Connection Public objRst As ADODB.Recordset Public objPwd As ADODB.Recordset Public objCmd As ADODB.Command Public Sub main() Set objConn = New ADODB.Connection Set objRst = New ADODB.Recordset Set objCmd = New ADODB.Command objConn.Provider = "MSDASQL.1" objConn.ConnectionString = "Password=pwdsa;Persist Security Info=True;User ID=idsa;Data Source=TESTING;Initial Catalog=TESTING" objConn.Open If objConn.State = adStateOpen Then MsgBox "Connexion with the server established", vbInformation, "prjTesting" Else MsgBox "Connexion Failed !", vbInformation, "prjTesting" End If End Sub Private Sub cmdValidate_Click() Open "C:\Testing\testing.txt " For Output As #1 With objRst Do While Not .EOF if !married = 1 and !age < 15 then write #1, "PersonID: "; !personid & " " Person must be greater 15 years in order to be married" .MoveNext Loop End With End Sub Private Sub Form_Load() main Set objRst = New ADODB.Recordset objRst.Open "tblPersondata", objConn, adOpenDynamic, adLockOptimistic End Sub ----------------------------- The problem with my code is that, it only checks for the first column only as with the other columns it does not. What am I doing wrong. Quick Help is appreciated. Thank you:(( phokojoe

    M 1 Reply Last reply
    0
    • P phokojoe

      I have entered data into a database table, "PersonData". It has 5 columns PersonNo Sex Age Married Education. Now I want to write a validation program in vb whereby it opens the "PersonData" and then checks that if person is married, then the spouse has to be of different sex. and if the pesron is married then the age has to be more than 15. There are many incosistencies that I would like my code to check, but if I can be helped with this ones I can handle the others. This I want to run for say about a thousands records. Then I write the validation messages to a text file. This is a sample of the code I have written: Option Explicit Public objConn As ADODB.Connection Public objRst As ADODB.Recordset Public objPwd As ADODB.Recordset Public objCmd As ADODB.Command Public Sub main() Set objConn = New ADODB.Connection Set objRst = New ADODB.Recordset Set objCmd = New ADODB.Command objConn.Provider = "MSDASQL.1" objConn.ConnectionString = "Password=pwdsa;Persist Security Info=True;User ID=idsa;Data Source=TESTING;Initial Catalog=TESTING" objConn.Open If objConn.State = adStateOpen Then MsgBox "Connexion with the server established", vbInformation, "prjTesting" Else MsgBox "Connexion Failed !", vbInformation, "prjTesting" End If End Sub Private Sub cmdValidate_Click() Open "C:\Testing\testing.txt " For Output As #1 With objRst Do While Not .EOF if !married = 1 and !age < 15 then write #1, "PersonID: "; !personid & " " Person must be greater 15 years in order to be married" .MoveNext Loop End With End Sub Private Sub Form_Load() main Set objRst = New ADODB.Recordset objRst.Open "tblPersondata", objConn, adOpenDynamic, adLockOptimistic End Sub ----------------------------- The problem with my code is that, it only checks for the first column only as with the other columns it does not. What am I doing wrong. Quick Help is appreciated. Thank you:(( phokojoe

      M Offline
      M Offline
      mr_12345
      wrote on last edited by
      #2

      I don't see in your code where married or age are getting set to values... Mike Lasseter

      P 1 Reply Last reply
      0
      • M mr_12345

        I don't see in your code where married or age are getting set to values... Mike Lasseter

        P Offline
        P Offline
        phokojoe
        wrote on last edited by
        #3

        Actually, What i am saying is that, the data is already in the database. Now the code I am writing will look for the inconsistencies and then write the message to the .txt file that I have specified with the ID of that particular person where there is incosistancies. In this, below Private Sub cmdValidate_Click() Open "C:\test\persondata.txt " For Output As #1 With objRst Do While Not .EOF If !married = 1 and age < 15 Then Write #1, "Person ID: "; !personid & " Too young to get married" .MoveNext Loop End With End Sub For the married code is 1 and I am checking that if that particular person is married then, his/her age must be greater than 15 otherwise write down the personid in the persondata.txt file so that it will be corrected. Since I will be checking many persons and the same time that is why I have enclosed the statement inside the DO WHILE NOT EOF. Please help phokojoe

        P 1 Reply Last reply
        0
        • P phokojoe

          Actually, What i am saying is that, the data is already in the database. Now the code I am writing will look for the inconsistencies and then write the message to the .txt file that I have specified with the ID of that particular person where there is incosistancies. In this, below Private Sub cmdValidate_Click() Open "C:\test\persondata.txt " For Output As #1 With objRst Do While Not .EOF If !married = 1 and age < 15 Then Write #1, "Person ID: "; !personid & " Too young to get married" .MoveNext Loop End With End Sub For the married code is 1 and I am checking that if that particular person is married then, his/her age must be greater than 15 otherwise write down the personid in the persondata.txt file so that it will be corrected. Since I will be checking many persons and the same time that is why I have enclosed the statement inside the DO WHILE NOT EOF. Please help phokojoe

          P Offline
          P Offline
          phokojoe
          wrote on last edited by
          #4

          Please help me with the above thread. Help is urgently needed. Actual, I am writing a code to validate my survey results whichI have used MS sql server 2000 as the backend and VB as the front end. Or can anybody help me with which is the appropriate software to use to validate the dataset. phokojoe

          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