Solved

compare txt file to database

Posted on 2002-04-16
5
187 Views
Last Modified: 2010-05-02
I was looking for source code or tool that will accomplish the below.I have a text file in format
txtfile:
firstname   lastname   date
john          mosely    3/2/2002
lisa          dunn      4/2/2002
mac           something  5/2/2002

Database in sql server
firstname   lastname   date
jeff         porter     3/3/2002
staci        watson     4/3/2002
mike         stern      2/1/2002

I want to compare the txtfile against the database,and where there is a match to input the results into a text file. I can use visualb 6.0 or asp.
0
Comment
Question by:jbird090897
5 Comments
 
LVL 18

Accepted Solution

by:
deighton earned 200 total points
ID: 6945197
   Dim sLine As String
    Dim sForename As String, sSurname As String, sDob As String

    Open "yourfile" For Input As #1
   
    Do Until EOF(1)
        Line Input #1, sLine
        sForename = Left(sLine, 14)
        sSurname = Mid(sLine, 15, 10)
        sDob = Mid(sLine, 25)
       
        'now you can check database
       
    Loop
0
 
LVL 45

Expert Comment

by:aikimark
ID: 6945275
your checking SQL should be:
"select from tablename where firstname = '" & Trim(sForename) & "' and lastname = '" & Trim(sSurname) & "' and [date] = #" & sDOB & "#"
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 6945771
Make ceertain your dates are in the correct format for SQL otherwise you may get one as dd/mm/yyyy and the other as mm/dd/yyyy

mlmcc
0
 
LVL 5

Expert Comment

by:kcm76
ID: 6945780
listening...
0
 
LVL 3

Expert Comment

by:dannic
ID: 6946250
You can also use ADODB yo access the text file.

If you use ADODB then you can use ASP as well as VB.

Private Sub cmdADOText_Click()
    'Variables and constants
    Dim objRs  As ADODB.Recordset
    Dim strPath As String
    Dim strDbConnection As String
    Const strDatabaseName As String = "ADOTEST.txt"
    '/Variables and constants
   
   
    'Database Path
    strPath = App.Path
   
    'Connection string
    strDbConnection = "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
                        "Dbq=" & strPath & ";" & _
                        "Extensions=asc,csv,tab,txt;" & _
                        "Persist Security Info=False;" & _
                        "DEFAULTDIR=" & strPath & ";" & _
                        "READONLY=False;"
                       
    'Create recordset
    Set objRs = New ADODB.Recordset
   
    'Set Recordset Properties
    With objRs
        .CursorType = adOpenStatic
        .ActiveConnection = strDbConnection
        .LockType = adLockPessimistic
        .Source = "SELECT * FROM " & _
                    strDatabaseName
        .Open
    End With
   
    'Check if the Recordset is open
    If objRs.State = adStateOpen Then
   
        'Loop until EOF
        Do While Not objRs.EOF
            ' zzz Debug
            Debug.Print "Firstname = " & objRs.Fields(0).Value & "   Lastname = " & _
                        objRs.Fields(1).Value & "   Date1 = " & objRs.Fields(2).Value
            ' /zzz Debug
           
            'Add code here to compare the data
            '
            'Add code here to compare the data
            objRs.MoveNext
        Loop
    Else
        MsgBox "Recordset is closed!"
    End If

    'Clean up
    If objRs.State = adStateOpen Then
        objRs.Close
    End If
    Set objRs = Nothing
    '/Clean up
End Sub

Good Luck!
dannic
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

820 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