Results 1 to 13 of 13

Thread: [RESOLVED] URGENT!!! Accessing a text file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    26

    Resolved [RESOLVED] URGENT!!! Accessing a text file

    Can any body connect a text file to access the contents as record source
    i.e., instead of MS-Access or SQL we have to use a text file as database and has to retrive, update,insert etc have to be done

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: URGENT!!! Accessing a text file

    Welcome to the forums.

    The only formal type of "connection" for a text file is simply to open it and do something with the contents.

    What is it, specifically that you need done and what does the file contain?

    If you can provide that information, myself or someone else, should be able to supply you with some sample code to get you started.

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: URGENT!!! Accessing a text file

    You can use text files as databases, however for a variety of reasons (such as security and reliability) I would recommend using a proper database of some kind if you can.

    In order to use a file as a data source, you will need to use a connection string like one of the ones below:

    "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=c:\path\;Extensions=csv,tab,txt;"

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\path\;Extended Properties=""text;HDR=Yes;FMT=Delimited"""

    I presume that the table names that you need to put into the SQL would be the name of the file(s) you are getting the data from (eg: "Select * From table1.txt").

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: URGENT!!! Accessing a text file

    Quote Originally Posted by si_the_geek
    You can use text files as databases, however for a variety of reasons (such as security and reliability) I would recommend using a proper database of some kind if you can.

    In order to use a file as a data source, you will need to use a connection string like one of the ones below:

    "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=c:\path\;Extensions=csv,tab,txt;"

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\path\;Extended Properties=""text;HDR=Yes;FMT=Delimited"""

    I presume that the table names that you need to put into the SQL would be the name of the file(s) you are getting the data from (eg: "Select * From table1.txt").
    Having never used a text file as a database, I actually didn't know there real live honest to God connect strings for them.

    What, if any, are the advantages of using a real connect string as opposed to simply doing an Open filename For Whatever As #1?

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: URGENT!!! Accessing a text file

    As long as the file has structured rows of data (delimited or by position, depending on the driver), you can access it using normal SQL statements, rather than having to create your own functions to do the same.

    Compared to other database options they are a big liability tho, as anybody can open them and change the data (as they must be plain text in order to work), and AFAIK only one user can access them at a time.

    On the upside they are obviously cheaper than many DBMS's (but as you know some good ones are free anyway), and are easy to distribute as only the standard drivers built into Windows are needed.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    26

    Re: URGENT!!! Accessing a text file

    Welcome to the forums.

    Actually, it has been asked by our external examiner,
    the question is as follows:

    Use a file as database (example:Login table which has fields username,password)

    we have to retrive or insert those fields to the login file.




    thxs for reply
    Last edited by pkirankumarreddy; Oct 20th, 2005 at 04:03 AM.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: URGENT!!! Accessing a text file

    If you use one of the connection strings in post #3 above you should be able to connect to a file as a database. If you need some example code, look at "ADO Tutorial" in my signature, which should give you a good start - feel free to ask if you get stuck

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    26

    Re: URGENT!!! Accessing a text file

    Hai guys,
    first I worked on that Mr.Si_The_Geek, its not working then only i posted this
    "When i did like that it is asking for which database u have to xport"

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: URGENT!!! Accessing a text file

    I'm afraid I have no idea what you mean by that.

    Care to try explaining again?

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: URGENT!!! Accessing a text file

    I think you are being asked to use two fields in a text file, not using a connection string. Doubt that he's ever seen it done that way either.
    Just use Print# and Input# to write and read uname, upass instead.

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: URGENT!!! Accessing a text file

    Actually David a connection string is required, as mentioned in posts #1 and #6 it must be used as a database (Update, Insert, etc.), rather than as a text file (Print#, Input#).

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: URGENT!!! Accessing a text file

    have to use a text file as database
    Sounds like a beginning VB class to me.

  13. #13
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: URGENT!!! Accessing a text file

    There is always a different option.

    Make a class that reads the text file, creates an ADO record set object, and then returns that object.

    Or pass a recordset in ByRef and and build it off manually reading your file.

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