| | |
Reading and Displaying a comma delimited text file to a table.
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2006
Posts: 7
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Jan 2007
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
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
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.
•
•
Join Date: Jun 2005
Posts: 107
Reputation:
Solved Threads: 3
This is an asp forum, ammarcool...not .NET.
ASP Syntax (Toggle Plain Text)
<% 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 Developer
When something seems too good to be true...it usually is
When something seems too good to be true...it usually is
•
•
Join Date: Feb 2007
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
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.
![]() |
Similar Threads
- how can we sort data from text file (C++)
- C++ Reading from a text file (C++)
- REgistering new members as groups in ipb (Growing an Online Community)
- PHP newbie, project feasibility (PHP)
Other Threads in the ASP Forum
- Previous Thread: Checkbox input to an Access DB via ASP and JScript
- Next Thread: string tokenizer
| Thread Tools | Search this Thread |
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection connection database databaseconnection dreamweaver excel fso iis msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption single specfic sqlserver sqlserverconnection windows7





