Results 1 to 3 of 3

Thread: Testing for Null in SQL Database Field

  1. #1

    Thread Starter
    Hyperactive Member cajsoft's Avatar
    Join Date
    Aug 2000
    Location
    Glasgow, Scotland
    Posts
    295

    Question

    Hello Gurus,
    I'm trying to test for a null or no data in a field from
    an MS SQL table.

    e.g I have 3 fields (Emp_Id,Emp_Name,Emp_Dob)
    I need to check if the Emp_Dob (Date field) has been entered.

    I thought just doing something like this would be enough:

    Code:
    cn.Connect = "uid=sa;pwd=;server=" & txtsvr & ";driver={SQL Server};database=" & txtdb & ";"
    cn.CursorDriver = rdUseIfNeeded
    cn.EstablishConnection rdDriverNoPrompt
    cn.GetData  <- Executes the SQL statement
       
       Set RS = cnclearjob.LastQueryResults
          Do Until RS.EOF
             If RS("Emp_Dob") = Null Then
                   Check1.Value = 1
                   MsgBox ("DOB Empty!")
             End If
             RS.Movenext
          Loop
    Unfortunately, VB doesnt recoginise that the empty value in the field, so ignores the 'IF' statement, even if I change the statement to (IF RS("Emp_Dob")= "" then ...... that doesnt work either!

    Anyone shed some light on this!!!??

    Cheers
    Craig.

  2. #2
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    Try

    Code:
    If IsNull(RS!Emp_Dob)
    VB6 sp5, SQL Server 2000, C#

    There are no stupid questions. Only stupid people.

  3. #3

    Thread Starter
    Hyperactive Member cajsoft's Avatar
    Join Date
    Aug 2000
    Location
    Glasgow, Scotland
    Posts
    295
    Hey, Thanks a lot.... that did the trick!!

    Thanks Again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width