Solved

compare txt file to database

Posted on 2002-04-16
5
183 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

760 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

23 Experts available now in Live!

Get 1:1 Help Now