954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

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

blakisa
Newbie Poster
7 posts since Dec 2006
Reputation Points: 10
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



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.

ammarcool
Newbie Poster
5 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 
jenny4u
Newbie Poster
12 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

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
%>
madmital
Junior Poster
120 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 
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.

wim2440
Newbie Poster
3 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

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.

wim2440
Newbie Poster
3 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You