Data exchange between text files and database files in ASP
The application of network databases is a very important component of WWW. It can be said that if a database is missing, the network will lose its soul. You can imagine how difficult it is to find a goal online without search engines like YAHOO and SOHU. Everyone becomes confused and loses their way in the vast sea of Internet. In fact, these search engines are the most typical applications of network databases. There are many direct operations on databases in ASP (Active Server Pages) technology. The following describes a method of passing data from text files to database files.
This text form is collected and transmitted to a fixed directory of the server by the terminal. The server reads the data and stores it in the local database. After the conversion, the text file is deleted. In this way, the terminal is responsible for collecting data and uploading it to the designated directory of the server in the given format. The server-side database is completely opaque to the terminal, ensuring the security of the server, and may be somewhat helpful for current network database applications.
Txttolib.asp
<html>
<head>
<meta http-equiv=refresh content=30;url=deltext.asp>
<meta http-equiv=Content-Type
content=text/html; charset=gb_2312-80>
<meta name=GENERATOR content=Microsoft FrontPage Express 2.0>
<title>[Convert text files to database files]</title>
</head>
<body bgcolor=#FFFFFF>
<align=center>
<p align=center><font color=#FF0000>The data is being processed, please wait!
<br>
</font><font color=#000000><align=center><%
str=server.mappath(/) 'Get the root directory of the server
Set fso = CreateObject(Scripting.FileSystemObject)
Set f = fso.GetFolder(str & /thetext)
Set fc = f.Files
k=1
For each f1 in fc
file(k)=f1.name 'get all file names under this path
k=k+1
next
%><% ii=1%><%
set fs = CreateObject(Scripting.FileSystemObject)%><%
while ii<k
response.write file(ii) & <br>
set textinstance=fs.opentextfile(str & /thetext/ & file(ii),1,false,false)'Open the file to read the data
while textinstance.atendofstream<> true 'If the file does not end
visitornum=textinstance.readline 'Read a line of data
j=0
cd=len(visitornum)
for i=1 to cd
if mid(visitornum,i,1)=, then 'The data is separated by ","
j=j+1
else
select case j' obtains each data value separately
case 0
me1=me1+mid(visitornum,i,1)
case 1
me2=me2+mid(visitornum,i,1)
case 2
me3=me3+mid(visitornum,i,1)
case 3
me4=me4+mid(visitornum,i,1)
case 4
me5=me5+mid(visitornum,i,1)
case 5
me6=me6+mid(visitornum,i,1)
end select
end if