Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Data from CSV to webpage in ASP

Posted on 2014-01-14
10
Medium Priority
?
441 Views
Last Modified: 2014-02-12
I have a program that periodicly writes out a .CSV file named data.csv to a specified directory. the amount of data never changes just the figures in the data. I want to be able to then pull that data into an .asp webpage table using vb script. my problem is that the program writes a new .csv file everytime and i cannot send the data to a specified file with a named range so i can use it as a table. Is there a way for me to pull the data without having a named range. just pull all the data and arrange it once in the ASP?
0
Comment
Question by:jlcannon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 39779501
yup absolutely, it's pretty straightforward. if you post your code I can help you translate it over to an asp page.
0
 

Author Comment

by:jlcannon
ID: 39779548
right now I have no code. In the past I have used code like this:
<%@ Language=VBScript %>
<!--#include file="includes/adovbs.inc"-->
<%

	vXlsFile = "virtual/documents/TechReport/GetIP21Data.xlsm"

	
vXlsFile = Server.Mappath(vXlsFile)

		ExcelConnString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
		"Data Source=" & chr(34) & vXlsFile & chr(34) & ";" & _
		"Extended Properties=" & chr(34) & "Excel 12.0 Xml;HDR=YES;"& chr(34)

		'Open Database Connection
		Set Conn = Server.CreateObject("ADODB.Connection")
		Conn.Open ExcelConnString 
%>
<html>
<head>
</head>
<body>
<%
				Sql = "SELECT * FROM tblData;"

				set RS = server.createobject("adodb.recordset")
	
	RS.open sql,Conn,adOpenForwardOnly,adLockReadOnly 
	
	if rs.bof and rs.eof then
		response.write "<br>No Records Returned!"
	else	
		Rs.Movefirst

%>

<table width="100%" border="1" cellpadding="0" cellspacing="0" class="stats-table">
<tr>	
      <th id="dailyInclude" style="width: 289px">&nbsp;</th>
      <th id="monthCOL" style="width: 244px">Tag</th>
      <th id="YTDCOL" style="width: 359px">Value</th>
      
							
</tr>
<%
do while not rs.eof
%>					
<tr>
<td class="rowType" style="width: 289px">Freeport</td>
<td align="center" style="width: 244px"><%=RS.Fields("TagName")%></td>
<td align="center" style="width: 359px"><%=RS.Fields("InputValue")%></td>
<%
	rs.movenext
loop
rs.close
set rs = nothing
%>

<%								
end if
Conn.Close
set conn = nothing

%>
</tr>
</table>
</body>

</html>

Open in new window

my issue is that I will not have that named range called tblData to use like a data table so dont know how to handle pulling the data in.
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39779550
Lets say the data layout is

Name, Email, Phone

and your data looks like

mike, mike@someplace.com, 1111111111

You would can parse each line using the split function.

line="mike, mike@someplace.com, 1111111111"
arrLine=split(line,",")
Name=arrLine(0)
Email=arrLine(1)
Phone=arrLine(2)

<table>
<tr><td>Name</td><td>Email</td><td>Phone</td></tr>
<%
line="mike, mike@someplace.com, 1111111111"
arrLine=split(line,",")
Name=arrLine(0)
Email=arrLine(1)
Phone=arrLine(2)
%>
<tr><td><%=Name%></td><td><%=Email%></td><td><%=Phone%></td></tr>
</table>

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 33

Expert Comment

by:Big Monty
ID: 39779573
where is the data coming from originally? you mention you write it out to  a csv file, but where does that data come from? is it pulled from a DB? if so, please post that code.
0
 

Author Comment

by:jlcannon
ID: 39779602
i follow except on place. the line="mike,mike@someplace,111111"
is that meaning i will have to do that for everyline of data? I am confused the data will be in 2 columns and will look similar to this:

SPH_626abo,2.2256
SPO_8R39G,55.235
GRP_URG43,795.24

the name of the file will be test.csv so using your method above would I have to have a line like line="SPH_626abo,2.2256"
              line="SPO_8R39G,55.235"
              line="GRP_URG43,795.24"
for each row of data in the csv or how would I implement this?
0
 

Author Comment

by:jlcannon
ID: 39779605
the data is pushed to the csv from a program called AspenTech IP21
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 2000 total points
ID: 39852927
1. the test.csv should be on the same server as the webpage.... may take more effort to get its path ?

2. from ... http://www.codeproject.com/Articles/251/Reading-a-text-file-in-ASP

note that a CSV file is a text file.
<%@ Language=VBScript %>

<%

	const CSVFileName = "virtual/documents/TechReport/GetIP21Data.CSV"


%>
<html>
<head>
</head>
<body>
<%

Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

' Create a filesystem object
Dim FSO
set FSO = server.createObject("Scripting.FileSystemObject")

' Map the logical path to the physical system path
Dim Filepath
Filepath = Server.MapPath(CSVFileName)

if FSO.FileExists(Filepath) Then

	%>

	<table width="100%" border="1" cellpadding="0" cellspacing="0" class="stats-table">
	<tr>	
		  <th id="dailyInclude" style="width: 289px">&nbsp;</th>
		  <th id="monthCOL" style="width: 244px">Tag</th>
		  <th id="YTDCOL" style="width: 359px">Value</th>
		  
								
	</tr>
	<%

    ' Get a handle to the file
    Dim file    
    set file = FSO.GetFile(Filepath)

    ' Get some info about the file
    Dim FileSize, txtLine, arrLine

    ' Open the file
    Dim TextStream
    Set TextStream = file.OpenAsTextStream(ForReading, TristateUseDefault)

    ' Read the file line by line
    Do While Not TextStream.AtEndOfStream

        txtLine = TextStream.readline
		arrLine=split(txtLine,",")         '********** this assumes that data is very well formed and does not contain strings with spaces !
		'there are ways to use a better parser...
		Response.write "<tr>" & vbcrlf
		Response.write "  <td class='rowType' style='width: 289px'>" & "Freeport"  & "</td>" & vbcrlf
		Response.write "  <td align='center' style='width: 244px'>" & arrLine(0) & "</td>" & vbcrlf    'the first item is Tag
		Response.write "  <td align='center' style='width: 359px'>" & arrLine(1)  & "</td>" & vbcrlf   'the second is lavue
		Response.write "</tr>" & vbcrlf

    Loop

    Set TextStream = nothing
    Response.write "</table>" & vbcrlf
Else

    Response.Write "<h3>No Records Returned!"</h3>"

End If

Set FSO = nothing

%>

</body>

</html>

Open in new window

0
 

Author Closing Comment

by:jlcannon
ID: 39853270
excellent, what I was looking for. Have googled this many times but never saw codeproject as a website.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question