|
-
Oct 19th, 2005, 04:07 AM
#1
Thread Starter
Junior Member
[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
-
Oct 19th, 2005, 05:28 AM
#2
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.
-
Oct 19th, 2005, 11:50 AM
#3
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").
-
Oct 19th, 2005, 11:52 AM
#4
Re: URGENT!!! Accessing a text file
 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?
-
Oct 19th, 2005, 05:09 PM
#5
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.
-
Oct 20th, 2005, 04:00 AM
#6
Thread Starter
Junior Member
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.
-
Oct 20th, 2005, 08:46 AM
#7
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
-
Oct 21st, 2005, 02:26 AM
#8
Thread Starter
Junior Member
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"
-
Oct 23rd, 2005, 06:01 PM
#9
Re: URGENT!!! Accessing a text file
I'm afraid I have no idea what you mean by that.
Care to try explaining again?
-
Oct 23rd, 2005, 06:10 PM
#10
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.
-
Oct 23rd, 2005, 07:24 PM
#11
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#).
-
Oct 23rd, 2005, 08:41 PM
#12
Re: URGENT!!! Accessing a text file
have to use a text file as database
Sounds like a beginning VB class to me.
-
Oct 23rd, 2005, 09:57 PM
#13
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|