Solved

Transfer contents of Sequential File to MS SQL Database

Posted on 1998-08-12
4
132 Views
Last Modified: 2010-05-18
I am importing a sequential data file with about 5000 lines of data (generated by an application coded in COBOL) to a MS SQL Database table...  Everything runs smoothly until the program hits a line that contains a period (as in:  2.5 grams).  After that it starts a new line and throws eveything out of synch.  Naturally everything crashes as the program tries to insert things into places where they don't belong...  Right now I work around it by changing all of the periods (.) to commas (.) using a text editor before I start the import process - but it's a ponderous work around...  Any ideas on how I can do this from inside VB or tell VB to accept the periods as part of the string
0
Comment
Question by:tlw2651
4 Comments
 
LVL 4

Expert Comment

by:tomook
ID: 1468674
What are you using for delimiters? Can you get the COBOL program to either quote delimit text ("2.5 grams"), or have your program interpret numbers as such? I guess I do not have enough information about the import method you are using. Please tell us how you are:
A) reading the file, and
B) what method you are using to post to SQL Server.
0
 

Expert Comment

by:electrick
ID: 1468675
I have an application that does pretty much the same thing.  I bring the data into a listbox first, that way the user can check and/or edit it.  Each line has several periods in it, and I don't have any problem with them.
If you want more info, let me know.
0
 
LVL 7

Accepted Solution

by:
kamall earned 100 total points
ID: 1468676
You can use the 'Line Input #X'  statement in your VB program to read data line by line from the file and save them to another file after changing the periods. Then start reading the data from the new file and do what you want.

Here is a sample code:

Open "c:\olddata.fil" For Input As #1
Open "c:\newdata.fil" For Output As #2
Do While Not EOF(1)
Line Input #1, X$
For I% = 1 To Len(X$)
    MyChar = Mid$(X$,I%,1)
    If MyChar <> "." Then
        Y$ = Y$ & MyChar
    Else
        Y$ = Y$ & "_"    'Put here the replacement character
    End If
Next
Print #2, Y$
Y$ = ""
Loop
Close 1
Close 2

Now you can work with the new file where all the periods '.' are replaced with '_'.
Hope that helps.
Regards
0
 

Author Comment

by:tlw2651
ID: 1468677
Kamall's answer is a good work around but I still don't understand why the program gets thrown off because of the commas.  I'm using the MID function to cut out the bits of information from the sequential and then calling a MS SQL stored procedure to store them in the appropriate rows of the database.  For some reason when the program encounters a comma it ignores the instructions pertaining to the length of the bit of text I want to cut out and starts the next bit.

Here's are 3 lines of the type of information I'm trying to extract.  The '[' were put in to make it easier to program initially.

000000003[01[20[029[29[200[SOLUTRAT 150MG X 20COMP. [        [        [01[000000000[000000000[000000000[+[000000000[0000000000000[0000000000000[00000000[0000000000002[0000000000002[00[04041998[0000000000002[0000000000002[04041998[29061997[04041998[00000000[000000000[ [0000[0000[ [ [ [000020000[+[000019000[01[000[2645071       [20[              [0000[029[29[SOLUTRAT 150M[01[SOLUTRAT 150MG[20[ [000000162[N[N[N[N[S[FAROPR      [*********[                                                            

000000004[01[30[029[29[077[NIVAQUINE COMP X 30      [        [        [01[000000000[000000000[000000000[+[000000000[0000000000000[0000000000000[00000000[0000000000000[0000000000000[00[00000000[0000000000000[0000000000000[00000000[30061997[00000000[00000000[000000000[ [0000[0000[ [ [ [000030000[+[000015000[01[000[0910092       [20[              [0000[029[29[NIVAQUINE COM[01[NIVAQUINE COMP[30[ [000000054[N[N[N[N[S[FAROPR      [*********[                                                            

000000005[01[20[029[29[807[BLAVIN 10MG COMP X 20    [        [        [01[000000000[000000000[000000000[+[000000000[0000000000000[0000000000000[00000000[0000000000000[0000000000000[00[00000000[0000000000000[0000000000000[00000000[29061997[00000000[21021998[000000000[ [0000[0000[ [ [ [000020000[+[000021000[01[000[3398712       [20[              [0000[029[29[BLAVIN 10MG C[01[BLAVIN 10MG CO[20[ [000000142[N[N[N[N[S[FAROPR      [*********[                                                            

Thanks for your responses
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

12 Experts available now in Live!

Get 1:1 Help Now