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
228 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

708 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