Link to home
Start Free TrialLog in
Avatar of Marisa Stevenson
Marisa StevensonFlag for United States of America

asked on

What are the Visual Basic 6.5 statements to check for a null value in a text column and/or to populate a sql server 2008 datetime column with null?

Visual Basic 6.5
Sql Server 2008
Windows Server 2000
Input: Pipe delimited text file
Output: SQL Server Table

Can you please provide a code snippet or example (or a reference to these) demonstrating how to check for a null value in a text column and/or how to populate a sql server 2008 datetime column (defined to allow nulls) with null?  I assume I may not need the latter if I have the former...

My application reads from a text file, and uses a value in the text file as an index to specific rows in the database table.  On a match, it rewrites (or inserts or deletes) the row depending on a status value.  The last column in each row of the text file contains a valid date time format OR nulls (both the source db from where the text file values are derived, and the target database being written to, have this column defined as a datetime that allows nulls).  The application works fine as long as it has a valid value in the last column, but if the value is null, it generates an error. VB is not my forte, but I believe the solution involves checking for a null in this column, and only moving the null value to the column when it isn't null (if it is null, simply don't populate the column).  Does this sound right?  

My apology that I don't have the exact error message.  I didn't trap it because I thought I'd be able to figure this out, and recreating it takes some time, so I hope it's not necessary since I am asking for an example of code and not necessarily a solution - I already identified the problem occurs when null values populate the personexpiredate column via a specific statement (ref below) so I believe skipping the statement if it is null will resolve it.    

This statement displays a message indicating a format problem if the input value is nulls - where ary(17) is the null value:  
 'rs!PersonExpireDate = Ary(17)

Assuming that's the best logic, it would be helpful to have a code example or statement syntax.  Am providing general app logic below.

If Not rs.NoMatch Then
                'ImageID DOES exist
                 If Ary(11) = "TERMINATED" Then 'DELETE the record.
                    rs.Delete
                    rs.Requery
                    IntRecordsDeleted = IntRecordsDeleted + 1
                ElseIf CDbl(rs!serialno) <= CDbl(Ary(0)) Then 'It's an update
                    rs.Edit
                    rs!serialno = Ary(0)
                    ' 10/29/2014 Source db has rows with a personexpiredate as null. Need to update the row if a value is                'provided or leave as nulls if not - It doesn't seem to like the statement below on nulls
                    'rs!PersonExpireDate = Ary(17)
                    rs.Update
                    rs.Requery
                    IntRecordsUpdated = IntRecordsUpdated + 1
                End If
            Else 'ImageID DOES NOT exist,
                 If Ary(11) <> "TERMINATED"
                    rs.AddNew
                    rs!serialno = Ary(0)
                    ' 10/29/2014 Dont think it likes the statement below
                    'rs!PersonExpireDate = Ary(17)
                    rs.Update
                    rs.Requery
SOLUTION
Avatar of Dany Balian
Dany Balian
Flag of Lebanon image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Marisa Stevenson

ASKER

Haven't added the code yet but it would appear that both of your responses would work.   Dany provided a direct response to my specific question, and jkalos suggested what is probably better logic for date fields,   Both are helpful to me, and I appreciate it.  I'll add the code today and "accept solutions" once I confirm that I have it working.