Results 1 to 3 of 3

Thread: Connectecting ADO with a text file

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 1999
    Posts
    2

    Post

    My question is
    How can i open a text file with ADO
    and if i want some specific line in the text file to be displayed in a textbox, would i be able to do that??



  2. #2
    Lively Member
    Join Date
    Oct 1999
    Posts
    101

    Post

    Create your ADO Recordset in VB and then populate it with the text file data using a Loop and the "Input #filenumber, varlist" Statement.

    In order to display a specific line in a text box, you can use a counter variable with the ADO recordset and loop through it in order to locate the line you are looking for. Populate the text box after the specific line has been found.

    If you want the data in the ADO recordset to replace your original text file, use a Loop and the "Write # Statement" that points to the original file.

    All the best.

    [This message has been edited by ChrisJackson (edited 11-02-1999).]

  3. #3
    New Member
    Join Date
    Nov 1999
    Location
    New Delhi
    Posts
    6

    Post

    '=========================================================================================
    'Here are the steps to access a Text Files using ADO's
    'Create a Text File Type DSN Using the ODBC
    'Type the following code in Visual Basic. Make sure the reference is set for ADO library.
    '=========================================================================================
    Dim ladorec As New ADODB.Recordset
    Dim ladoCon As New ADODB.Connection
    Private Sub Form_Load()
    '=========================================================================================
    'Suppose you name the
    'DSN As TEXTDSN
    'And the Text File is named as a.txt
    'The format of Text File is as Below

    'Name Address Telephone
    'A XYZ 1234567
    'B X12 1234567
    'C Z12 1234567
    '=========================================================================================
    ladoCon.Open "DSN=TEXTDSN"
    Set ladorec = ladoCon.Execute("Select name,address,telephone from a.txt")
    While Not ladorec.EOF
    If ladorec("name") = "A" then
    Text1.Text = ladorec("A")
    Endif
    ladorec.MoveNext
    Wend

    End Sub
    '=========================================================================================
    'Get back for any further clarification
    '=========================================================================================


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width