Importing csv file into a database table was a need when I was upgrading one of my website for a new functionality. This snippet to import csv file will be very handy when there are bulk records in csv file and you want them to be imported into a table or just display on screen. The code will parse csv file using FSO(File System Object) in asp and will display on screen as a HTML table.
Code:
<%
dim csv_to_import,counter,line,fso,objFile
csv_to_import="csv_to_be_imported.csv"   ' CSV file to be imported
set fso = createobject("scripting.filesystemobject")
set objFile = fso.opentextfile(server.mappath(csv_to_import))
str_imported_data="<table cellpadding='3' cellspacing='1' border='1'>"
Do Until objFile.AtEndOfStream
      line = split(objFile.ReadLine,",")
      str_imported_data=str_imported_data&"<tr>"
   total_records=ubound(line)
   for i=0 to total_records
      if i>0 then
         str_imported_data=str_imported_data&"<td>"&line(i)&"</td>"
      else
         str_imported_data=str_imported_data&"<th>"&line(i)&"</th>"
      end if
   next
      str_imported_data=str_imported_data&"</tr>" & chr(13)
Loop
str_imported_data=str_imported_data&"<caption>Total Number of Records: "&total_records&"</caption></table>"
objFile.Close
response.Write str_imported_data
%>