Solved

Transfer contents of Sequential File to MS SQL Database

Posted on 1998-08-12
4
133 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

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 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

11 Experts available now in Live!

Get 1:1 Help Now