Solved

Transfer contents of Sequential File to MS SQL Database

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

724 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