By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,856 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,856 IT Pros & Developers. It's quick & easy.

how to find whether particular value is present in database

P: 11
hi..
i hav created a form which gets empid as input and retrieve data from database and display information about employee.now wen i get empid as input i should check with d table tat empid shold exist. if does not exist i should display a message..
can anyone suggest me d code or idea how can i do it.
Feb 5 '09 #1
Share this Question
Share on Google+
8 Replies


ck9663
Expert 2.5K+
P: 2,878
Sounds like an assignment. What do you have so far?

-- CK
Feb 5 '09 #2

P: 11
i hav done for inserting,deleting,updatin,displayin..
now i hav to validate

thanks & regards
Sri
Feb 6 '09 #3

ck9663
Expert 2.5K+
P: 2,878
Could you post what you have so far?

-- CK
Feb 13 '09 #4

P: 11
i hav created forms for insertin emp detail,deletin,updatin and viewing..wen i insert i need to check whether the id i am giving exist already in a database or not.. if exist i should display an error mess..
u need the code of front end wat i hav done or the database..im sorry i don get u whether i should post my entire code or not.

thanks
sri
Feb 13 '09 #5

ck9663
Expert 2.5K+
P: 2,878
Use Search Condition


-- CK
Feb 14 '09 #6

OuTCasT
100+
P: 374
Expand|Select|Wrap|Line Numbers
  1. Private Function ValidateEmployeeID(ByVal EmployeeCode As String) As Boolean
  2.         Dim sqlCon As SqlConnection = Nothing
  3.         Dim sqlCom As SqlCommand = Nothing
  4.         Dim lookupID As String
  5.  
  6.         lookupID = Nothing
  7.  
  8.         'Check for EmployeeCode
  9.         If ((EmployeeCode Is Nothing)) Then
  10.             MsgBox("[ValidateEmployeeID] Input Validation of EmployeeID Failed", MsgBoxStyle.Critical)
  11.             Return False
  12.         End If
  13.         Try
  14.             sqlCon = New SqlConnection("Data Source=./SQLEXPRESS;Initial Catalog=<DBNAME>;Integrated Security=True")
  15.             sqlCon.Open()
  16.  
  17.             'Create sqlCommand to retrieve EmployeeId
  18.             sqlCom = New SqlCommand("select [employeeId] from EmployeeDetails where [employeeid]=@EmployeeID COLLATE SQL_Latin1_General_CP1_CI_AS", sqlCon)
  19.             sqlCom.Parameters.Add("@EmployeeID", SqlDbType.VarChar, 25)
  20.             sqlCom.Parameters("@EmployeeID").Value = txtEmployeeCode.Text
  21.  
  22.             lookupID = sqlCom.ExecuteScalar
  23.  
  24.             sqlCom.Dispose()
  25.             sqlCon.Dispose()
  26.         Catch ex As Exception
  27.             sqlCom.Dispose()
  28.             sqlCon.Dispose()
  29.             MsgBox("Employee ID Already Exists Please make another selection", MsgBoxStyle.Information)
  30.         End Try
  31.         If (lookupID Is Nothing) Then
  32.             Return False
  33.         End If
  34.         Return (String.Compare(lookupID.ToUpper, txtEmployeeCode.Text.ToUpper, False) = 0)
  35.     End Function
Feb 16 '09 #7

P: 1
' will not work
' If ((EmployeeCode Is Nothing)) Then
' MsgBox("[ValidateEmployeeID] Input Validation of EmployeeID Failed", MsgBoxStyle.Critical)
' Return False
' End If
' this will fire!
If IsNull(EmployeeCode) Then
MsgBox("[ValidateEmployeeID] Input Validation of EmployeeID Failed", MsgBoxStyle.Critical)
Return False
End If
Feb 17 '09 #8

OuTCasT
100+
P: 374
@Gradwohl
This is not really needed actually.
Feb 17 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.