Solved

Transfer contents of Sequential File to MS SQL Database

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

749 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