p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_howto thread: How do I insert data from text file to database?


Message #1 by "Arstan Jusupov" <arstan@v...> on Tue, 24 Dec 2002 03:37:53
Here is what I've done so far.
Default.asp is the file where you point which text file to insert into the 
db. The text structure is like this:

********my.txt********
546546545 , 45654654
46456546544, 45664645
54654654 , 4546546
*******end of my.txt****

So what I want is to Split each line into two different variables and 
insert them into two different cell in the db.
Thanks.

*******************************Default.asp******************
<!--#include file="includes/header.asp"-->
<!--#include file="includes/data_store.asp"-->
<!--#include file="includes/adovbs.inc"-->
<form action="upload.asp" method="post" name="form1">
  <table width="650" border="0" cellpadding="0" cellspacing="0" 
bgcolor="#CCCCCC">
    <tr> 
      <td><table width="100%" border="0" cellspacing="1" cellpadding="3">
          <tr> 
            <td width="31%" class="bg1">CouponType:</td>
            <td width="69%" class="bg2"> 
              <%
		  Dim objRS, strSQL
		  set objRS=server.CreateObject("adodb.recordset")
		  strSQL="select * from coupontype "
		  objRS.Open strSQL, strConnect, adOpenStatic, 
adLockReadOnly, adCmdText
		  if objRS.EOF then
		  response.write "No coupons yet!"
		  Else
		  %>
		  
              <select name="txtCoupontypeid" class="drop" 
id="txtCoupontypeid">
          <%
		  while not objRS.EOF
		  %>      <option value="<%=objRS("coupontypeid")%>"><%
=objRS("couponname")%></option>
<%
ObjRS.MoveNext
Wend
End if
%>
              </select></td>
          </tr>
          <tr> 
            <td class="bg1">Coupon text file:</td>
            <td class="bg2"> <input name="txtFile" type="file" 
class="drop" id="txtFile" size="20" enctype="multipart/form-data">  </td>
          </tr>
          <tr> 
            <td class="bg1">Percentage:</td>
            <td class="bg2"><input name="txtPercantage" type="text" 
class="drop" id="txtPercantage2" size="3"></td>
          </tr>
          <tr> 
            <td class="bg1">Note:</td>
            <td class="bg2"><input name="txtNote" type="text" class="drop" 
id="txtNote2"></td>
          </tr>
          <tr> 
            <td class="bg1">&nbsp;</td>
            <td class="bg2"><input name="Submit" type="submit" 
class="drop" value="Ok Upload"> 
              <input name="Submit2" type="reset" class="drop" value="Clear 
Form"></td>
          </tr>
        </table></td>
    </tr>
  </table>
</form>
</body>
</html>
**************************************End of Default.Asp*************


********************************Upload.Asp***************************

<!--#include file="includes/header.asp"-->
<!--#include file="includes/data_store.asp"-->
<!--#include file="includes/adovbs.inc"-->
<%
Dim  strCoupontype, strPercantage, strFile, Dosya, objFileSys, strCid, 
DosyaAcma, TextFile , strData
strFile=request.form("txtFile")
strCid=request.Form("txtCouponTypeid")

response.Write  strFile
response.Write("<br>")
response.Write strCid
response.Write("<br>")
response.Write strCouponType
response.write "<br>"

Set DosyaAcma=Server.CreateObject ("Scripting.FileSystemObject" ) 
Set TextFile=DosyaAcma.OpenTextFile (strFile , 1) 


While not TextFile.AtEndOfStream 
strData = TextFile.ReadLine
response.Write strData
response.write "<br>"
Wend

TextFile.Close 
Set TextFile=Nothing 
Set DosyaAcma=Nothing 

%>

***************************End of Upload.Asp***********************

  Return to Index