User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP section within the Web Development category of DaniWeb, a massive community of 456,420 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,631 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP advertiser: Lunarpages ASP Web Hosting
Views: 8479 | Replies: 5
Reply
Join Date: Dec 2006
Posts: 7
Reputation: blakisa is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
blakisa blakisa is offline Offline
Newbie Poster

Reading and Displaying a comma delimited text file to a table.

  #1  
Dec 11th, 2006
Hi All,

Anyone know of an efficient way to read a data text file in comma delimited format and displaying the information to a table. I read some of the previous post, but they did not seem too informative.

Basically,

Check file existance, display if not availible
Load variables from file
Diplay variables to table
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Location: Colombo
Posts: 5
Reputation: ammarcool is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ammarcool ammarcool is offline Offline
Newbie Poster

Solution Re: Reading and Displaying a comma delimited text file to a table.

  #2  
Jan 26th, 2007
Originally Posted by blakisa View Post
Hi All,

Anyone know of an efficient way to read a data text file in comma delimited format and displaying the information to a table. I read some of the previous post, but they did not seem too informative.

Basically,

Check file existance, display if not availible
Load variables from file
Diplay variables to table

hii!

just try the following code: hope it might help you! i have used the Microsoft Text Driver to read the content from the CSV file strieghtly & populating a Grid with the fetched data!

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dtRecords As DataTable
Dim dr As DataRow
dtRecords = GetDataTable("SELECT * FROM members2.csv")
DataGridView1.DataSource = dtRecords

End Sub

Private Function GetConnection()
Return "Driver={Microsoft Text Driver (*.txt; *.csv)};HDR=YES;Extensions=asc,csv,tab,txt;Dbq= " & Application.StartupPath & "\;"
End Function

Private Function GetDataTable(ByVal sql As String)
Dim rt As DataTable
Dim da As OdbcDataAdapter
Dim con As OdbcConnection
Dim cmd As OdbcCommand
Try
rt = New DataTable()
ds = New DataSet()
da = New OdbcDataAdapter()
con = New OdbcConnection(GetConnection())
cmd = New OdbcCommand(sql, con)
da.SelectCommand = cmd
da.Fill(ds)
rt = ds.Tables(0)
Label1.Text = "Records in the CSV:" + CStr(ds.Tables(0).Rows.Count)
Catch ex As Exception
rt = Nothing
MsgBox(ex.Message)
End Try
Return rt
End Function

regards,

Ammar.
Reply With Quote  
Join Date: Feb 2007
Posts: 12
Reputation: jenny4u is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jenny4u jenny4u is offline Offline
Newbie Poster

Re: Reading and Displaying a comma delimited text file to a table.

  #3  
Feb 20th, 2007
Reply With Quote  
Join Date: Jun 2005
Location: Denmark, EU
Posts: 102
Reputation: madmital is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
madmital madmital is offline Offline
Junior Poster

Re: Reading and Displaying a comma delimited text file to a table.

  #4  
Feb 25th, 2007
This is an asp forum, ammarcool...not .NET.

<%
set fso = server.createobject("scripting.filesystemobject")
set file = fso.opentextfile(server.mappath(".") & "/data.txt", 1)
data = file.readall()
file.close
lines = split(data, VbCrLf)

response.write "<table border=1>"

for each line in lines
	subline = split(line, ",")
	response.write "<tr>"
	for each val in subline
		response.write "<td>" & val & "</td>"
	next
	response.write "</tr>"
next

response.write "</table>"

set fso = nothing : set file = nothing
%>
Web Programmer
Reply With Quote  
Join Date: Feb 2007
Location: belgium
Posts: 2
Reputation: wim2440 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
wim2440 wim2440 is offline Offline
Newbie Poster

Re: Reading and Displaying a comma delimited text file to a table.

  #5  
Feb 25th, 2007
Originally Posted by blakisa View Post
Hi All,

Anyone know of an efficient way to read a data text file in comma delimited format and displaying the information to a table. I read some of the previous post, but they did not seem too informative.

Basically,

Check file existance, display if not availible
Load variables from file
Diplay variables to table

==>
hi,
i usually open the file in excel, manupulate the data as needed and then import the file into a table in autocad, using simple cut & paste.
best regards and succes
wim.
Reply With Quote  
Join Date: Feb 2007
Location: belgium
Posts: 2
Reputation: wim2440 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
wim2440 wim2440 is offline Offline
Newbie Poster

Re: Reading and Displaying a comma delimited text file to a table.

  #6  
Feb 25th, 2007
hi,
i usually open the file in excel, manupulate the data as needed and then import the file into a table in autocad, using simple cut & paste.
best regards and succes
wim.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP Forum

All times are GMT -4. The time now is 1:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC