Solved

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?

Posted on 2014-10-30
3
232 Views
Last Modified: 2014-10-31
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
0
Comment
Question by:Marisa Stevenson
3 Comments
 
LVL 11

Assisted Solution

by:Dany Balian
Dany Balian earned 250 total points
ID: 40414605
just try this:
if not isnull(Ary(17)) then
rs!PersonExpireDate = Ary(17)
end if

Open in new window

0
 
LVL 12

Accepted Solution

by:
jkaios earned 250 total points
ID: 40414947
You need to validate the date value from the text first before inserting it into the db.

If IsDate(Ary(17)) Then
   rs!PersonExpireDate = Ary(17)
End If

Open in new window

0
 

Author Comment

by:Marisa Stevenson
ID: 40415737
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Python 2.7 - French characters 6 58
VBA filters 2 50
vb6 connector to SQL Server 2 34
converting visio 2010 to powerpoint 2010  - formatting issues 5 11
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now