Validation of Textbox
-
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
-
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
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 functionhope 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!
-
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 functionhope 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!
ups sorry, i think i made mistake in that code, the line
r=cmd.executenonquery
should have been
r=cmd.executescalar
, sorry...:-O
-
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 functionhope 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!
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