how to find whether particular value is present in database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • srig
    New Member
    • Feb 2009
    • 11

    how to find whether particular value is present in database

    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.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Sounds like an assignment. What do you have so far?

    -- CK

    Comment

    • srig
      New Member
      • Feb 2009
      • 11

      #3
      i hav done for inserting,delet ing,updatin,dis playin..
      now i hav to validate

      thanks & regards
      Sri

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        Could you post what you have so far?

        -- CK

        Comment

        • srig
          New Member
          • Feb 2009
          • 11

          #5
          how to find whether particular value is present in database

          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

          Comment

          • ck9663
            Recognized Expert Specialist
            • Jun 2007
            • 2878

            #6
            Use Search Condition


            -- CK

            Comment

            • OuTCasT
              Contributor
              • Jan 2008
              • 374

              #7
              Code:
              Private Function ValidateEmployeeID(ByVal EmployeeCode As String) As Boolean
                      Dim sqlCon As SqlConnection = Nothing
                      Dim sqlCom As SqlCommand = Nothing
                      Dim lookupID As String
              
                      lookupID = Nothing
              
                      'Check for EmployeeCode
                      If ((EmployeeCode Is Nothing)) Then
                          MsgBox("[ValidateEmployeeID] Input Validation of EmployeeID Failed", MsgBoxStyle.Critical)
                          Return False
                      End If
                      Try
                          sqlCon = New SqlConnection("Data Source=./SQLEXPRESS;Initial Catalog=<DBNAME>;Integrated Security=True")
                          sqlCon.Open()
              
                          'Create sqlCommand to retrieve EmployeeId
                          sqlCom = New SqlCommand("select [employeeId] from EmployeeDetails where [employeeid]=@EmployeeID COLLATE SQL_Latin1_General_CP1_CI_AS", sqlCon)
                          sqlCom.Parameters.Add("@EmployeeID", SqlDbType.VarChar, 25)
                          sqlCom.Parameters("@EmployeeID").Value = txtEmployeeCode.Text
              
                          lookupID = sqlCom.ExecuteScalar
              
                          sqlCom.Dispose()
                          sqlCon.Dispose()
                      Catch ex As Exception
                          sqlCom.Dispose()
                          sqlCon.Dispose()
                          MsgBox("Employee ID Already Exists Please make another selection", MsgBoxStyle.Information)
                      End Try
                      If (lookupID Is Nothing) Then
                          Return False
                      End If
                      Return (String.Compare(lookupID.ToUpper, txtEmployeeCode.Text.ToUpper, False) = 0)
                  End Function

              Comment

              • Gradwohl
                New Member
                • Feb 2009
                • 1

                #8
                your problem

                ' will not work
                ' If ((EmployeeCode Is Nothing)) Then
                ' MsgBox("[ValidateEmploye eID] Input Validation of EmployeeID Failed", MsgBoxStyle.Cri tical)
                ' Return False
                ' End If
                ' this will fire!
                If IsNull(Employee Code) Then
                MsgBox("[ValidateEmploye eID] Input Validation of EmployeeID Failed", MsgBoxStyle.Cri tical)
                Return False
                End If

                Comment

                • OuTCasT
                  Contributor
                  • Jan 2008
                  • 374

                  #9
                  Originally posted by Gradwohl
                  ' will not work
                  ' If ((EmployeeCode Is Nothing)) Then
                  ' MsgBox("[ValidateEmploye eID] Input Validation of EmployeeID Failed", MsgBoxStyle.Cri tical)
                  ' Return False
                  ' End If
                  ' this will fire!
                  If IsNull(Employee Code) Then
                  MsgBox("[ValidateEmploye eID] Input Validation of EmployeeID Failed", MsgBoxStyle.Cri tical)
                  Return False
                  End If
                  This is not really needed actually.

                  Comment

                  Working...