?
Solved

compare txt file to database

Posted on 2002-04-16
5
Medium Priority
?
192 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
[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
5 Comments
 
LVL 18

Accepted Solution

by:
deighton earned 600 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 46

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 101

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

Industry Leaders: 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

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses

718 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