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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maro to copy and paste from one worksheet to another based on a condition 11 55
TT Auto Dashboard 13 95
CONDITIONAL MAX STATEMENT IN T-SQL 3 73
Android development question 2 54
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

830 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