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
Printable View
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
Welcome to the forums. :wave:
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.
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. :eek:Quote:
Originally Posted by si_the_geek
What, if any, are the advantages of using a real connect string as opposed to simply doing an Open filename For Whatever As #1?
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.
Welcome to the forums. :wave:
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
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 :)
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"
:confused: I'm afraid I have no idea what you mean by that.
Care to try explaining again?
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.
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#).
Sounds like a beginning VB class to me.Quote:
have to use a text file as database
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.