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
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

705 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